diff --git a/src/commands/FuzzySuggester.ts b/src/commands/FuzzySuggester.ts index 0c912da..34d2de0 100644 --- a/src/commands/FuzzySuggester.ts +++ b/src/commands/FuzzySuggester.ts @@ -1,6 +1,6 @@ import { FuzzySuggestModal, FuzzyMatch } from 'obsidian'; import MyPlugin from "../main"; -import {i18nConfig} from "../lang/I18n"; +import { i18nConfig } from "../lang/I18n"; /** * Simple interface for what should be displayed and stored for suggester @@ -38,7 +38,7 @@ export class FuzzySuggester extends FuzzySuggestModal{ return item.name } - onChooseItem(item: DatabaseList, evt:MouseEvent | KeyboardEvent): void { } + onChooseItem(item: DatabaseList, evt: MouseEvent | KeyboardEvent): void { } onChooseSuggestion(item: FuzzyMatch, evt: MouseEvent | KeyboardEvent): void { this.callback(item.item, evt) diff --git a/src/commands/NotionCommands.ts b/src/commands/NotionCommands.ts index dcfb90b..2ca4b2b 100644 --- a/src/commands/NotionCommands.ts +++ b/src/commands/NotionCommands.ts @@ -1,7 +1,7 @@ -import {i18nConfig} from "src/lang/I18n"; -import {Editor, MarkdownView} from "obsidian"; -import {FuzzySuggester, DatabaseList} from "./FuzzySuggester"; -import {uploadCommandGeneral, uploadCommandNext} from "../upload/uploadCommand"; +import { i18nConfig } from "src/lang/I18n"; +import { Editor, MarkdownView } from "obsidian"; +import { FuzzySuggester, DatabaseList } from "./FuzzySuggester"; +import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand"; import ObsidianSyncNotionPlugin from "src/main"; @@ -14,7 +14,7 @@ interface Command { // create the commands list export default class RibbonCommands { - plugin: ObsidianSyncNotionPlugin; + plugin: ObsidianSyncNotionPlugin; Ncommand: Command[] = []; @@ -55,22 +55,22 @@ export default class RibbonCommands { }); } - async ribbonDisplay() { - const NcommandList: DatabaseList[] = []; + async ribbonDisplay() { + const NcommandList: DatabaseList[] = []; - this.Ncommand.map(command => NcommandList.push( - { - name:command.name, - match: command.editorCallback - } - ) - ); + this.Ncommand.map(command => NcommandList.push( + { + name: command.name, + match: command.editorCallback + } + ) + ); - const fusg = new FuzzySuggester(this.plugin); + const fusg = new FuzzySuggester(this.plugin); - fusg.setSuggesterData(NcommandList); - await fusg.display(async (results) => {await results.match()}) - }; + fusg.setSuggesterData(NcommandList); + await fusg.display(async (results) => { await results.match() }) + }; // if the setting has been changed, try to rebuild the command list async updateCommand() { diff --git a/src/lang/I18n.ts b/src/lang/I18n.ts index e5fe195..46973b0 100644 --- a/src/lang/I18n.ts +++ b/src/lang/I18n.ts @@ -24,13 +24,13 @@ export const I18n: { [key: string]: any } = { NotionUserText: "Enter your notion ID", NotionGeneralSettingHeader: "General Notion Database Settings", NotionGeneralButton: "Notion General command switch", - NotionGeneralButtonDesc: "Open this option, Sync to Notion General Database command will be displayed in the command palette", - NotionCustomTitle: "Customise column name", - NotionCustomTitleDesc: "Modify the column name of the Notion database, default (off)", - NotionCustomTitleName: "Preferred title name", - NotionCustomTitleNameDesc: "Enter the preferred title name for the first column of the Notion database", - NotionCustomTitleText: "Enter the name", - NotYetFinish: + NotionGeneralButtonDesc: "Open this option, Sync to Notion General Database command will be displayed in the command palette", + NotionCustomTitle: "Customise column name", + NotionCustomTitleDesc: "Modify the column name of the Notion database, default (off)", + NotionCustomTitleName: "Preferred title name", + NotionCustomTitleNameDesc: "Enter the preferred title name for the first column of the Notion database", + NotionCustomTitleText: "Enter the name", + NotYetFinish: "Not finished. This function will be available in the next version", PlaceHolder: "Enter database Name", "notion-logo": "Share to NotionNext", @@ -47,9 +47,9 @@ export const I18n: { [key: string]: any } = { "The 'NNon' property is missing in the settings. Please set it up.", "set-api-id": "Please set up the notion API and database ID in the settings tab.", - NotionCustomSettingHeader: "Notion Custom Database Settings", - NotionCustomButton: "Notion Customised command switch", - NotionCustomButtonDesc: "Open this option, Sync to Notion Customised Database command will be displayed in the command palette", + NotionCustomSettingHeader: "Notion Custom Database Settings", + NotionCustomButton: "Notion Customised command switch", + NotionCustomButtonDesc: "Open this option, Sync to Notion Customised Database command will be displayed in the command palette", }, zh: { ribbonIcon: "分享到 NotionNext", @@ -58,8 +58,8 @@ export const I18n: { [key: string]: any } = { CommandName: "分享到 NotionNext", CommandIDGeneral: "share-to-notion", CommandNameGeneral: "分享到 Notion 普通数据库", - NotionNextButton: "NotionNext 同步命令开关", - NotionNextButtonDesc: "打开此选项,NotionNext 同步将显示在命令面板中", + NotionNextButton: "NotionNext 同步命令开关", + NotionNextButtonDesc: "打开此选项,NotionNext 同步将显示在命令面板中", NotionNextSettingHeader: "NotionNext 数据库参数设置", NotionAPI: "Notion API 令牌", NotionAPIDesc: "显示为密码", @@ -75,14 +75,14 @@ export const I18n: { [key: string]: any } = { "你的 Notion ID(可选),分享链接类似:https://username.notion.site/,你的 Notion ID 是 [username]", NotionUserText: "输入你的 Notion ID", NotionGeneralSettingHeader: "普通 Notion 数据库设置", - NotionGeneralButton: "普通数据库同步命令开关", - NotionGeneralButtonDesc: "打开此选项,同步到普通数据库命令将显示在命令面板中", + NotionGeneralButton: "普通数据库同步命令开关", + NotionGeneralButtonDesc: "打开此选项,同步到普通数据库命令将显示在命令面板中", NotionCustomTitle: "修改 Notion 数据库表头开关", - NotionCustomTitleDesc: "自定义Notion 数据库第一列表头,默认关闭", - NotionCustomTitleName: "想要修改的表头名", - NotionCustomTitleNameDesc: "输入你想要修改的notion数据库的表头名", - NotionCustomTitleText: "输入表头名", - NotYetFinish: "未完成。此功能将在之后版本中提供", + NotionCustomTitleDesc: "自定义Notion 数据库第一列表头,默认关闭", + NotionCustomTitleName: "想要修改的表头名", + NotionCustomTitleNameDesc: "输入你想要修改的notion数据库的表头名", + NotionCustomTitleText: "输入表头名", + NotYetFinish: "未完成。此功能将在之后版本中提供", PlaceHolder: "输入数据库名称", "notion-logo": "分享到NotionNext", "sync-success": "同步到NotionNext成功:\n", @@ -94,9 +94,9 @@ export const I18n: { [key: string]: any } = { "设置标签失败,请检查文件的frontmatter,或者在插件设置中关闭设置tags开关", NNonMissing: "未设置'NNon'属性,请在插件设置中选择NotionNext数据库。", "set-api-id": "请在插件设置中设置notion API和database ID", - NotionCustomSettingHeader: "Notion 自定义数据库设置", - NotionCustomButton: "Notion 自定义数据库同步命令开关", - NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中", + NotionCustomSettingHeader: "Notion 自定义数据库设置", + NotionCustomButton: "Notion 自定义数据库同步命令开关", + NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中", }, }; diff --git a/src/main.ts b/src/main.ts index 6910774..5352417 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import {App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting} from "obsidian"; -import {addIcons} from 'src/ui/icon'; -import {Upload2NotionGeneral} from "src/upload/upload_general/Upload2NotionGeneral"; -import {Upload2NotionNext} from "src/upload/upload_next/Upload2NotionNext"; -import {i18nConfig} from "src/lang/I18n"; +import { App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting } from "obsidian"; +import { addIcons } from 'src/ui/icon'; +import { Upload2NotionGeneral } from "src/upload/upload_general/Upload2NotionGeneral"; +import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext"; +import { i18nConfig } from "src/lang/I18n"; import ribbonCommands from "src/commands/NotionCommands"; import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs"; diff --git a/src/ui/settingTabs.ts b/src/ui/settingTabs.ts index 8be0ad7..e8782f0 100644 --- a/src/ui/settingTabs.ts +++ b/src/ui/settingTabs.ts @@ -17,6 +17,7 @@ export interface PluginSettings { CustomButton: boolean; notionAPICustom: string; databaseIDCustom: string; + [key: string]: any; } export const DEFAULT_SETTINGS: PluginSettings = { @@ -53,9 +54,9 @@ export class ObsidianSettingTab extends PluginSettingTab { // General Settings containerEl.createEl('h2', { text: i18nConfig.GeneralSetting }); - this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl) + this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl, 'bannerUrl') - this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser) + this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser, 'notionUser') containerEl.createEl('h2', { text: i18nConfig.NotionNextSettingHeader }) @@ -80,10 +81,10 @@ export class ObsidianSettingTab extends PluginSettingTab { const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton) - this.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext) + this.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext, 'notionAPINext') const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton) - this.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext) + this.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext, 'databaseIDNext') // General Database Settings @@ -129,7 +130,7 @@ export class ObsidianSettingTab extends PluginSettingTab { ); const CustomNameEl = this.createStyleDiv('custom-name', this.plugin.settings.CustomTitleButton); - this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.plugin.settings.CustomTitleName) + this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.plugin.settings.CustomTitleName, 'CustomTitleName') // new Setting(containerEl) // .setName("Convert tags(optional)") @@ -144,11 +145,11 @@ export class ObsidianSettingTab extends PluginSettingTab { // ); const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton); - this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPIGeneral) + this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPIGeneral, 'notionAPIGeneral') const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton); - this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDGeneral) + this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDGeneral, 'databaseIDGeneral') // Custom Database Settings @@ -177,12 +178,12 @@ export class ObsidianSettingTab extends PluginSettingTab { private updateSettingEl(element: HTMLElement, commandValue: boolean) { element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none"; element.style.paddingTop = commandValue ? "0.75em" : "0"; - element.style.display = commandValue? "block" : "none"; + element.style.display = commandValue ? "block" : "none"; element.style.alignItems = "center"; } // function to add one setting element in the setting tab. - private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any) { + private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) { if (type === 'password') { return new Setting(containerEl) .setName(name) @@ -193,11 +194,10 @@ export class ObsidianSettingTab extends PluginSettingTab { .setPlaceholder(placeholder) .setValue(holderValue) .onChange(async (value) => { - holderValue = value; + this.plugin.settings[settingsKey] = value; // Update the plugin settings directly await this.plugin.saveSettings(); }) - } - ) + }); } else if (type === 'toggle') { return new Setting(containerEl) .setName(name) @@ -206,13 +206,13 @@ export class ObsidianSettingTab extends PluginSettingTab { toggle .setValue(holderValue) .onChange(async (value) => { - holderValue = value; + this.plugin.settings[settingsKey] = value; // Update the plugin settings directly await this.plugin.saveSettings(); await this.plugin.commands.updateCommand(); }) - ) + ); } else if (type === 'text') { - new Setting(containerEl) + return new Setting(containerEl) .setName(name) .setDesc(desc) .addText((text) => @@ -220,11 +220,11 @@ export class ObsidianSettingTab extends PluginSettingTab { .setPlaceholder(placeholder) .setValue(holderValue) .onChange(async (value) => { - holderValue = value; + this.plugin.settings[settingsKey] = value; // Update the plugin settings directly await this.plugin.saveSettings(); await this.plugin.commands.updateCommand(); }) - ) + ); } } diff --git a/src/upload/updateYaml.ts b/src/upload/updateYaml.ts index a55e21e..5e90a85 100644 --- a/src/upload/updateYaml.ts +++ b/src/upload/updateYaml.ts @@ -1,6 +1,6 @@ -import {App, Notice, TFile} from "obsidian"; +import { App, Notice, TFile } from "obsidian"; import ObsidianSyncNotionPlugin from "../main"; -import {PluginSettings} from "../ui/settingTabs"; +import { PluginSettings } from "../ui/settingTabs"; export async function updateYamlInfo( yamlContent: string, @@ -9,7 +9,7 @@ export async function updateYamlInfo( app: App, plugin: ObsidianSyncNotionPlugin, ) { - let {url, id} = res.json + let { url, id } = res.json // replace www to notionID const { notionUser } = plugin.settings; diff --git a/src/upload/uploadCommand.ts b/src/upload/uploadCommand.ts index 158399e..fbd2c78 100644 --- a/src/upload/uploadCommand.ts +++ b/src/upload/uploadCommand.ts @@ -1,11 +1,11 @@ -import {i18nConfig} from "../lang/I18n"; -import {App, Notice} from "obsidian"; -import {Upload2NotionNext} from "./upload_next/Upload2NotionNext"; -import {Upload2NotionGeneral} from "./upload_general/Upload2NotionGeneral"; -import {PluginSettings} from "../ui/settingTabs"; +import { i18nConfig } from "../lang/I18n"; +import { App, Notice } from "obsidian"; +import { Upload2NotionNext } from "./upload_next/Upload2NotionNext"; +import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral"; +import { PluginSettings } from "../ui/settingTabs"; import ObsidianSyncNotionPlugin from "../main"; -import {getNowFileMarkdownContentNext} from "./upload_next/getMarkdownNext"; -import {getNowFileMarkdownContentGeneral} from "./upload_general/getMarkdownGeneral"; +import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext"; +import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral"; export async function uploadCommandNext( plugin: ObsidianSyncNotionPlugin, @@ -13,7 +13,7 @@ export async function uploadCommandNext( app: App, ) { - const {notionAPINext, databaseIDNext} = settings; + const { notionAPINext, databaseIDNext } = settings; // Check if NNon exists // if (NNon === undefined) { @@ -29,10 +29,10 @@ export async function uploadCommandNext( return; } - const {markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime} = await getNowFileMarkdownContentNext(app, settings) + const { markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime } = await getNowFileMarkdownContentNext(app, settings) if (markDownData) { - const {basename} = nowFile; + const { basename } = nowFile; const upload = new Upload2NotionNext(plugin); const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app); @@ -53,7 +53,7 @@ export async function uploadCommandGeneral( app: App, ) { - const{ notionAPIGeneral, databaseIDGeneral} = settings; + const { notionAPIGeneral, databaseIDGeneral } = settings; // Check if the user has set up the Notion API and database ID if (notionAPIGeneral === "" || databaseIDGeneral === "") { @@ -62,10 +62,10 @@ export async function uploadCommandGeneral( return; } - const {markDownData, nowFile,cover, tags} = await getNowFileMarkdownContentGeneral(app, settings) + const { markDownData, nowFile, cover, tags } = await getNowFileMarkdownContentGeneral(app, settings) if (markDownData) { - const {basename} = nowFile; + const { basename } = nowFile; const upload = new Upload2NotionGeneral(plugin); const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app); diff --git a/src/upload/upload_general/Upload2NotionGeneral.ts b/src/upload/upload_general/Upload2NotionGeneral.ts index dcc5555..427e3c3 100644 --- a/src/upload/upload_general/Upload2NotionGeneral.ts +++ b/src/upload/upload_general/Upload2NotionGeneral.ts @@ -4,15 +4,15 @@ import { markdownToBlocks, } from "@tryfabric/martian"; import * as yamlFrontMatter from "yaml-front-matter"; // import * as yaml from "yaml" import MyPlugin from "src/main"; -import {PluginSettings} from "../../ui/settingTabs"; -import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral"; -import {updateYamlInfo} from "../updateYaml"; +import { PluginSettings } from "../../ui/settingTabs"; +import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral"; +import { updateYamlInfo } from "../updateYaml"; export class Upload2NotionGeneral extends UploadBaseGeneral { settings: PluginSettings; constructor(plugin: MyPlugin) { - super(plugin); + super(plugin); } // 因为需要解析notion的block进行对比,非常的麻烦, @@ -22,7 +22,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { title: string, cover: string, tags: string[], - childArr: any + childArr: any, ) { await this.deletePage(notionID) @@ -50,7 +50,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { database_id: this.plugin.settings.databaseIDGeneral, }, properties: { - title: { + [this.plugin.settings.CustomTitleButton ? this.plugin.settings.CustomTitleName : 'title']: { title: [ { text: {