From ae4488546c0892ad5e8820060a8129c194cf6462 Mon Sep 17 00:00:00 2001 From: Jiaxin Peng Date: Thu, 6 Nov 2025 16:27:24 +0000 Subject: [PATCH 1/2] feat: add auto sync database list handling and notifications for missing entries --- src/lang/locale/en.ts | 1 + src/lang/locale/ja.ts | 1 + src/lang/locale/zh.ts | 1 + src/main.ts | 41 +++++++++++++++++++++++++++---- src/upload/updateYaml.ts | 7 ++++++ src/utils/frontmatter.ts | 52 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 src/utils/frontmatter.ts diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 6552294..a8fc216 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -86,6 +86,7 @@ export const en = { CheckConsole: "Check the console for more information \n opt+cmd+i/ctrl+shift+i", SettingsMigrated: "✨ Plugin settings updated! Auto sync feature added, check plugin settings", AutoSyncNoNotionID: "⚠️ Auto sync skipped: This document has not been synced to Notion, please upload manually first", + AutoSyncMissingDatabaseList: "⚠️ Auto sync skipped: Add an \"aytosync-database\" list in the frontmatter to choose databases", AutoSyncMultipleSync: "🔄 Auto sync: Syncing to {count} database(s)...", AutoSyncFailed: "Auto sync to {database} failed: {error}", AutoSyncError: "Auto sync failed for {filename}: {error}", diff --git a/src/lang/locale/ja.ts b/src/lang/locale/ja.ts index a5cec6a..c0594da 100644 --- a/src/lang/locale/ja.ts +++ b/src/lang/locale/ja.ts @@ -78,6 +78,7 @@ export const ja = { CheckConsole: "詳細情報を確認するには、コンソールを開いてください \n opt+cmd+i/ctrl+shift+i", SettingsMigrated: "✨ プラグイン設定が更新されました!自動同期機能が追加されました。設定を確認してください", AutoSyncNoNotionID: "⚠️ 自動同期をスキップ:このドキュメントは Notion に同期されていません。まず手動でアップロードしてください", + AutoSyncMissingDatabaseList: "⚠️ 自動同期をスキップ:frontmatter に aytosync-database リストを設定してください", AutoSyncMultipleSync: "🔄 自動同期:{count} 個のデータベースに同期中...", AutoSyncFailed: "{database} への自動同期に失敗しました:{error}", AutoSyncError: "{filename} の自動同期に失敗しました:{error}", diff --git a/src/lang/locale/zh.ts b/src/lang/locale/zh.ts index 2cf418a..1bb21dc 100644 --- a/src/lang/locale/zh.ts +++ b/src/lang/locale/zh.ts @@ -81,6 +81,7 @@ export const zh = { CheckConsole: "opt+cmd+i/ctrl+shift+i,\n打开控制台查看更多信息", SettingsMigrated: "✨ 插件设置已更新!新增自动同步功能,请在设置中查看", AutoSyncNoNotionID: "⚠️ 自动同步跳过:此文档未同步到 Notion,请先手动上传", + AutoSyncMissingDatabaseList: "⚠️ 自动同步跳过:请在 frontmatter 中设置 aytosync-database 列表", AutoSyncMultipleSync: "🔄 自动同步:正在同步到 {count} 个数据库...", AutoSyncFailed: "自动同步到 {database} 失败:{error}", AutoSyncError: "自动同步 {filename} 失败:{error}", diff --git a/src/main.ts b/src/main.ts index 3d34a81..83dfc8a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { i18nConfig } from "src/lang/I18n"; import ribbonCommands from "src/commands/NotionCommands"; import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS, DatabaseDetails } from "src/ui/settingTabs"; import { uploadCommandNext, uploadCommandGeneral, uploadCommandCustom } from "src/upload/uploadCommand"; +import { AUTO_SYNC_DATABASE_KEY, parseAutoSyncDatabaseList } from "src/utils/frontmatter"; // Remember to rename these classes and interfaces! @@ -17,6 +18,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { private syncingFiles: Set = new Set(); private lastFrontmatterCache: Map = new Map(); private lastContentHashCache: Map = new Map(); + private missingAutoSyncNoticeShown: Set = new Set(); async onload() { await this.loadSettings(); @@ -67,6 +69,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { } this.lastFrontmatterCache.clear(); this.lastContentHashCache.clear(); + this.missingAutoSyncNoticeShown.clear(); } async loadSettings() { @@ -327,21 +330,50 @@ export default class ObsidianSyncNotionPlugin extends Plugin { } } - // Find all databases this file belongs to by checking for NotionID-{abName} - const foundDatabases: Array<{ dbDetails: DatabaseDetails, notionId: string }> = []; + const autoSyncTargets = parseAutoSyncDatabaseList(frontMatter[AUTO_SYNC_DATABASE_KEY]); + if (autoSyncTargets.length === 0) { + if (!this.missingAutoSyncNoticeShown.has(file.path)) { + new Notice(i18nConfig.AutoSyncMissingDatabaseList, 10000); + this.missingAutoSyncNoticeShown.add(file.path); + } + console.log(`[AutoSync] No auto sync database list found in ${file.path}`); + return; + } + + this.missingAutoSyncNoticeShown.delete(file.path); + + const dbByShortName = new Map(); for (const key in this.settings.databaseDetails) { const dbDetails = this.settings.databaseDetails[key]; - const notionIDKey = `NotionID-${dbDetails.abName}`; + dbByShortName.set(dbDetails.abName.toLowerCase(), dbDetails); + } + const foundDatabases: Array<{ dbDetails: DatabaseDetails, notionId: string }> = []; + const unresolvedTargets: string[] = []; + + for (const target of autoSyncTargets) { + const lookupKey = target.toLowerCase(); + const dbDetails = dbByShortName.get(lookupKey); + + if (!dbDetails) { + unresolvedTargets.push(target); + continue; + } + + const notionIDKey = `NotionID-${dbDetails.abName}`; if (frontMatter[notionIDKey]) { foundDatabases.push({ - dbDetails: dbDetails, + dbDetails, notionId: String(frontMatter[notionIDKey]) }); } } + if (unresolvedTargets.length > 0) { + console.log(`[AutoSync] Frontmatter auto sync targets not found in settings: ${unresolvedTargets.join(", ")}`); + } + // If no NotionID found, notify user to upload manually first if (foundDatabases.length === 0) { console.log(`[AutoSync] No NotionID found in ${file.path}, skipping auto sync`); @@ -403,4 +435,3 @@ export default class ObsidianSyncNotionPlugin extends Plugin { } } } - diff --git a/src/upload/updateYaml.ts b/src/upload/updateYaml.ts index be5ab01..3bdafb3 100644 --- a/src/upload/updateYaml.ts +++ b/src/upload/updateYaml.ts @@ -2,6 +2,7 @@ import { App, Notice, TFile } from "obsidian"; import ObsidianSyncNotionPlugin from "../main"; import { DatabaseDetails } from "../ui/settingTabs"; import { i18nConfig } from "src/lang/I18n"; +import { AUTO_SYNC_DATABASE_KEY, ensureAutoSyncDatabaseEntry } from "src/utils/frontmatter"; export async function updateYamlInfo( yamlContent: string, @@ -33,6 +34,12 @@ export async function updateYamlInfo( // add new notionID and link yamlContent[notionIDKey] = id; (NotionLinkDisplay) ? yamlContent[linkKey] = url : null; + + // ensure auto sync database list contains current short name + yamlContent[AUTO_SYNC_DATABASE_KEY] = ensureAutoSyncDatabaseEntry( + yamlContent[AUTO_SYNC_DATABASE_KEY], + abName + ); }); try { diff --git a/src/utils/frontmatter.ts b/src/utils/frontmatter.ts new file mode 100644 index 0000000..bb8b2b7 --- /dev/null +++ b/src/utils/frontmatter.ts @@ -0,0 +1,52 @@ +export const AUTO_SYNC_DATABASE_KEY = "aytosync-database"; + +function toCandidateList(value: unknown): string[] { + if (Array.isArray(value)) { + return value.map(item => String(item ?? "").trim()); + } + + if (typeof value === "string") { + if (value.includes(",")) { + return value.split(",").map(item => item.trim()); + } + return [value.trim()]; + } + + return []; +} + +export function parseAutoSyncDatabaseList(value: unknown): string[] { + const candidates = toCandidateList(value) + .map(name => name.replace(/^\[|\]$/g, "").trim()) // strip stray brackets + .filter(Boolean); + + const seen = new Map(); + for (const name of candidates) { + const key = name.toLowerCase(); + if (!seen.has(key)) { + seen.set(key, name); + } + } + + return Array.from(seen.values()); +} + +export function ensureAutoSyncDatabaseEntry(value: unknown, abName: string): string[] { + const current = parseAutoSyncDatabaseList(value); + const lower = abName.toLowerCase(); + + let contains = false; + const updated = current.map(name => { + if (name.toLowerCase() === lower) { + contains = true; + return abName; + } + return name; + }); + + if (!contains) { + updated.push(abName); + } + + return updated; +} From bb4b75c82e254b7790a9e388d430be62449e4503 Mon Sep 17 00:00:00 2001 From: Jiaxin Peng Date: Thu, 6 Nov 2025 16:43:24 +0000 Subject: [PATCH 2/2] feat: add auto sync frontmatter key configuration and update related messages --- src/lang/locale/en.ts | 4 +++- src/lang/locale/ja.ts | 26 ++++++++++++++------------ src/lang/locale/zh.ts | 4 +++- src/main.ts | 32 +++++++++++++++++++++++++++----- src/ui/settingTabs.ts | 18 +++++++++++++++++- src/upload/updateYaml.ts | 7 ++++--- src/utils/frontmatter.ts | 13 ++++++++++++- 7 files changed, 80 insertions(+), 24 deletions(-) diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index a8fc216..b3b1e50 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -37,6 +37,8 @@ export const en = { NotionLinkDisplayDesc: "Default is ON, if you want to hide the link in the front matter, please turn it off", AutoSync: "Auto Sync", AutoSyncDesc: "Automatically sync to Notion when frontmatter or content is modified (requires existing NotionID)", + AutoSyncFrontmatterKey: "Auto Sync Frontmatter Key", + AutoSyncFrontmatterKeyDesc: "Set the frontmatter property name that lists which databases should auto sync (defaults to autosync-database).", AutoSyncDelay: "Auto Sync Delay (seconds)", AutoSyncDelayDesc: "How many seconds to wait after document modification before triggering auto sync (default: 5 seconds, minimum: 2 seconds)", AutoSyncDelayText: "Enter delay in seconds", @@ -86,7 +88,7 @@ export const en = { CheckConsole: "Check the console for more information \n opt+cmd+i/ctrl+shift+i", SettingsMigrated: "✨ Plugin settings updated! Auto sync feature added, check plugin settings", AutoSyncNoNotionID: "⚠️ Auto sync skipped: This document has not been synced to Notion, please upload manually first", - AutoSyncMissingDatabaseList: "⚠️ Auto sync skipped: Add an \"aytosync-database\" list in the frontmatter to choose databases", + AutoSyncMissingDatabaseList: "⚠️ Auto sync skipped: Add a \"{key}\" entry in the frontmatter to choose databases", AutoSyncMultipleSync: "🔄 Auto sync: Syncing to {count} database(s)...", AutoSyncFailed: "Auto sync to {database} failed: {error}", AutoSyncError: "Auto sync failed for {filename}: {error}", diff --git a/src/lang/locale/ja.ts b/src/lang/locale/ja.ts index c0594da..c25a2f4 100644 --- a/src/lang/locale/ja.ts +++ b/src/lang/locale/ja.ts @@ -31,13 +31,15 @@ export const ja = { NotionUser: "Notion ID(ユーザー名、任意)", NotionUserDesc: "共有リンクから取得(例:https://username.notion.site)。Notion IDは[username]です", NotionUserText: "Notion IDを入力", - NotionLinkDisplay: "Notionリンク表示", - NotionLinkDisplayDesc: "デフォルトはONです。front matterにリンクを非表示にしたい場合は、オフにしてください", - AutoSync: "自動同期", - AutoSyncDesc: "frontmatter またはコンテンツが変更されたときに自動的に Notion に同期します(NotionID が必要)", - AutoSyncDelay: "自動同期遅延時間(秒)", - AutoSyncDelayDesc: "ドキュメントの変更後、自動同期をトリガーするまでの待機時間(デフォルト:5秒、最小:2秒)", - AutoSyncDelayText: "遅延秒数を入力", + NotionLinkDisplay: "Notionリンク表示", + NotionLinkDisplayDesc: "デフォルトはONです。front matterにリンクを非表示にしたい場合は、オフにしてください", + AutoSync: "自動同期", + AutoSyncDesc: "frontmatter またはコンテンツが変更されたときに自動的に Notion に同期します(NotionID が必要)", + AutoSyncFrontmatterKey: "自動同期 frontmatter キー", + AutoSyncFrontmatterKeyDesc: "自動同期するデータベースを列挙する frontmatter のプロパティ名を設定します(デフォルトは autosync-database)。", + AutoSyncDelay: "自動同期遅延時間(秒)", + AutoSyncDelayDesc: "ドキュメントの変更後、自動同期をトリガーするまでの待機時間(デフォルト:5秒、最小:2秒)", + AutoSyncDelayText: "遅延秒数を入力", NotionGeneralSettingHeader: "一般的なNotionデータベース設定", NotionGeneralButton: "一般的なNotion同期", NotionGeneralButtonDesc: "このオプションを開くと、一般的なNotionデータベース同期コマンドがコマンドパレットに表示されます(デフォルト:ON)", @@ -75,11 +77,11 @@ export const ja = { CopyErrorMessage: "自動コピーに失敗しました", BlockUploaded: "ブロックがアップロードされました", ExtraBlockUploaded: "追加ブロックがアップロードされました", - CheckConsole: "詳細情報を確認するには、コンソールを開いてください \n opt+cmd+i/ctrl+shift+i", - SettingsMigrated: "✨ プラグイン設定が更新されました!自動同期機能が追加されました。設定を確認してください", - AutoSyncNoNotionID: "⚠️ 自動同期をスキップ:このドキュメントは Notion に同期されていません。まず手動でアップロードしてください", - AutoSyncMissingDatabaseList: "⚠️ 自動同期をスキップ:frontmatter に aytosync-database リストを設定してください", - AutoSyncMultipleSync: "🔄 自動同期:{count} 個のデータベースに同期中...", + CheckConsole: "詳細情報を確認するには、コンソールを開いてください \n opt+cmd+i/ctrl+shift+i", + SettingsMigrated: "✨ プラグイン設定が更新されました!自動同期機能が追加されました。設定を確認してください", + AutoSyncNoNotionID: "⚠️ 自動同期をスキップ:このドキュメントは Notion に同期されていません。まず手動でアップロードしてください", + AutoSyncMissingDatabaseList: "⚠️ 自動同期をスキップ:frontmatter に \"{key}\" 項目を追加してください", + AutoSyncMultipleSync: "🔄 自動同期:{count} 個のデータベースに同期中...", AutoSyncFailed: "{database} への自動同期に失敗しました:{error}", AutoSyncError: "{filename} の自動同期に失敗しました:{error}", "reach-mobile-limit": "ブロック数が100の制限を超えています。デスクトップ版プラグインを使用してください", diff --git a/src/lang/locale/zh.ts b/src/lang/locale/zh.ts index 1bb21dc..e3caa5c 100644 --- a/src/lang/locale/zh.ts +++ b/src/lang/locale/zh.ts @@ -37,6 +37,8 @@ export const zh = { NotionLinkDisplayDesc: "默认开启,如果你不想在front matter中显示链接,请关闭", AutoSync: "自动同步", AutoSyncDesc: "当检测到文档的 frontmatter 或内容发生修改时,自动同步到 Notion(需要文档已有 NotionID)", + AutoSyncFrontmatterKey: "自动同步 Frontmatter 键名", + AutoSyncFrontmatterKeyDesc: "设置用于列出自动同步数据库的 frontmatter 属性名称(默认 autosync-database)。", AutoSyncDelay: "自动同步延迟时间(秒)", AutoSyncDelayDesc: "文档修改后等待多少秒才触发自动同步,避免频繁同步(默认:5秒,最小:2秒)", AutoSyncDelayText: "输入延迟秒数", @@ -81,7 +83,7 @@ export const zh = { CheckConsole: "opt+cmd+i/ctrl+shift+i,\n打开控制台查看更多信息", SettingsMigrated: "✨ 插件设置已更新!新增自动同步功能,请在设置中查看", AutoSyncNoNotionID: "⚠️ 自动同步跳过:此文档未同步到 Notion,请先手动上传", - AutoSyncMissingDatabaseList: "⚠️ 自动同步跳过:请在 frontmatter 中设置 aytosync-database 列表", + AutoSyncMissingDatabaseList: "⚠️ 自动同步跳过:请在 frontmatter 中添加 \"{key}\" 项来指定数据库", AutoSyncMultipleSync: "🔄 自动同步:正在同步到 {count} 个数据库...", AutoSyncFailed: "自动同步到 {database} 失败:{error}", AutoSyncError: "自动同步 {filename} 失败:{error}", diff --git a/src/main.ts b/src/main.ts index 83dfc8a..4d66e07 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import { i18nConfig } from "src/lang/I18n"; import ribbonCommands from "src/commands/NotionCommands"; import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS, DatabaseDetails } from "src/ui/settingTabs"; import { uploadCommandNext, uploadCommandGeneral, uploadCommandCustom } from "src/upload/uploadCommand"; -import { AUTO_SYNC_DATABASE_KEY, parseAutoSyncDatabaseList } from "src/utils/frontmatter"; +import { DEFAULT_AUTO_SYNC_DATABASE_KEY, parseAutoSyncDatabaseList, resolveAutoSyncKey } from "src/utils/frontmatter"; // Remember to rename these classes and interfaces! @@ -92,6 +92,10 @@ export default class ObsidianSyncNotionPlugin extends Plugin { if (typeof this.settings.NotionLinkDisplay !== 'boolean') { this.settings.NotionLinkDisplay = DEFAULT_SETTINGS.NotionLinkDisplay; } + if (typeof this.settings.autoSyncFrontmatterKey !== 'string') { + this.settings.autoSyncFrontmatterKey = DEFAULT_AUTO_SYNC_DATABASE_KEY; + } + this.settings.autoSyncFrontmatterKey = resolveAutoSyncKey(this.settings.autoSyncFrontmatterKey); // Ensure databaseDetails exists if (!this.settings.databaseDetails || typeof this.settings.databaseDetails !== 'object') { @@ -102,7 +106,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin { const needsSave = !loadedData || loadedData.autoSync === undefined || loadedData.autoSyncDelay === undefined || - loadedData.NotionLinkDisplay === undefined; + loadedData.NotionLinkDisplay === undefined || + loadedData.autoSyncFrontmatterKey === undefined; if (needsSave) { const migratedFields = []; @@ -134,6 +139,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { autoSync: this.settings.autoSync, autoSyncDelay: this.settings.autoSyncDelay, NotionLinkDisplay: this.settings.NotionLinkDisplay, + autoSyncFrontmatterKey: this.settings.autoSyncFrontmatterKey, databaseCount: Object.keys(this.settings.databaseDetails || {}).length }); } @@ -156,6 +162,20 @@ export default class ObsidianSyncNotionPlugin extends Plugin { console.warn('[Settings] Invalid databaseDetails, resetting to empty object'); this.settings.databaseDetails = {}; } + if (typeof this.settings.autoSyncFrontmatterKey !== 'string' || this.settings.autoSyncFrontmatterKey.trim().length === 0) { + console.warn('[Settings] Invalid autoSyncFrontmatterKey, resetting to default'); + this.settings.autoSyncFrontmatterKey = DEFAULT_AUTO_SYNC_DATABASE_KEY; + } else { + this.settings.autoSyncFrontmatterKey = resolveAutoSyncKey(this.settings.autoSyncFrontmatterKey); + } + } + + resetAutoSyncNoticeCache() { + this.missingAutoSyncNoticeShown.clear(); + } + + getAutoSyncFrontmatterKey(): string { + return resolveAutoSyncKey(this.settings.autoSyncFrontmatterKey); } async addDatabaseDetails(dbDetails: DatabaseDetails) { @@ -330,14 +350,16 @@ export default class ObsidianSyncNotionPlugin extends Plugin { } } - const autoSyncTargets = parseAutoSyncDatabaseList(frontMatter[AUTO_SYNC_DATABASE_KEY]); + const autoSyncKey = this.getAutoSyncFrontmatterKey(); + const autoSyncTargets = parseAutoSyncDatabaseList(frontMatter[autoSyncKey]); if (autoSyncTargets.length === 0) { if (!this.missingAutoSyncNoticeShown.has(file.path)) { - new Notice(i18nConfig.AutoSyncMissingDatabaseList, 10000); + const message = i18nConfig.AutoSyncMissingDatabaseList.replace('{key}', autoSyncKey); + new Notice(message, 10000); this.missingAutoSyncNoticeShown.add(file.path); } - console.log(`[AutoSync] No auto sync database list found in ${file.path}`); + console.log(`[AutoSync] No auto sync database list found in ${file.path} using key "${autoSyncKey}"`); return; } diff --git a/src/ui/settingTabs.ts b/src/ui/settingTabs.ts index b97f28d..0cb5975 100644 --- a/src/ui/settingTabs.ts +++ b/src/ui/settingTabs.ts @@ -5,6 +5,7 @@ import { SettingModal } from "./settingModal"; import { PreviewModal } from "./PreviewModal"; import { EditModal } from "./EditModal"; import { DeleteModal } from "./DeleteModal"; +import { DEFAULT_AUTO_SYNC_DATABASE_KEY } from "src/utils/frontmatter"; export interface PluginSettings { NextButton: boolean; @@ -15,6 +16,7 @@ export interface PluginSettings { NotionLinkDisplay: boolean; autoSync: boolean; autoSyncDelay: number; + autoSyncFrontmatterKey: string; proxy: string; GeneralButton: boolean; tagButton: boolean; @@ -53,6 +55,7 @@ export const DEFAULT_SETTINGS: PluginSettings = { NotionLinkDisplay: true, autoSync: false, autoSyncDelay: 5, + autoSyncFrontmatterKey: DEFAULT_AUTO_SYNC_DATABASE_KEY, proxy: "", GeneralButton: true, tagButton: true, @@ -94,6 +97,20 @@ export class ObsidianSettingTab extends PluginSettingTab { this.createSettingEl(containerEl, i18nConfig.AutoSync, i18nConfig.AutoSyncDesc, 'toggle', i18nConfig.AutoSync, this.plugin.settings.autoSync, 'autoSync') + new Setting(containerEl) + .setName(i18nConfig.AutoSyncFrontmatterKey) + .setDesc(i18nConfig.AutoSyncFrontmatterKeyDesc) + .addText((text) => + text + .setPlaceholder(DEFAULT_AUTO_SYNC_DATABASE_KEY) + .setValue(this.plugin.settings.autoSyncFrontmatterKey ?? "") + .onChange(async (value) => { + this.plugin.settings.autoSyncFrontmatterKey = value; + await this.plugin.saveSettings(); + this.plugin.resetAutoSyncNoticeCache(); + }) + ); + // Auto Sync Delay setting - only visible when autoSync is enabled this.autoSyncDelayContainer = containerEl.createDiv(); const delaySetting = new Setting(this.autoSyncDelayContainer) @@ -350,4 +367,3 @@ export class ObsidianSettingTab extends PluginSettingTab { } } - diff --git a/src/upload/updateYaml.ts b/src/upload/updateYaml.ts index 3bdafb3..4545c3e 100644 --- a/src/upload/updateYaml.ts +++ b/src/upload/updateYaml.ts @@ -2,7 +2,7 @@ import { App, Notice, TFile } from "obsidian"; import ObsidianSyncNotionPlugin from "../main"; import { DatabaseDetails } from "../ui/settingTabs"; import { i18nConfig } from "src/lang/I18n"; -import { AUTO_SYNC_DATABASE_KEY, ensureAutoSyncDatabaseEntry } from "src/utils/frontmatter"; +import { ensureAutoSyncDatabaseEntry } from "src/utils/frontmatter"; export async function updateYamlInfo( yamlContent: string, @@ -18,6 +18,7 @@ export async function updateYamlInfo( const { abName } = dbDetails const notionIDKey = `NotionID-${abName}`; const linkKey = `link-${abName}`; + const autoSyncKey = plugin.getAutoSyncFrontmatterKey(); if (notionUser !== "") { // replace url str "www" to notionID @@ -36,8 +37,8 @@ export async function updateYamlInfo( (NotionLinkDisplay) ? yamlContent[linkKey] = url : null; // ensure auto sync database list contains current short name - yamlContent[AUTO_SYNC_DATABASE_KEY] = ensureAutoSyncDatabaseEntry( - yamlContent[AUTO_SYNC_DATABASE_KEY], + yamlContent[autoSyncKey] = ensureAutoSyncDatabaseEntry( + yamlContent[autoSyncKey], abName ); }); diff --git a/src/utils/frontmatter.ts b/src/utils/frontmatter.ts index bb8b2b7..1a9d2a5 100644 --- a/src/utils/frontmatter.ts +++ b/src/utils/frontmatter.ts @@ -1,4 +1,15 @@ -export const AUTO_SYNC_DATABASE_KEY = "aytosync-database"; +export const DEFAULT_AUTO_SYNC_DATABASE_KEY = "autosync-database"; + +export function resolveAutoSyncKey(rawKey: unknown): string { + if (typeof rawKey === "string") { + const trimmed = rawKey.trim(); + if (trimmed.length > 0) { + return trimmed; + } + } + + return DEFAULT_AUTO_SYNC_DATABASE_KEY; +} function toCandidateList(value: unknown): string[] { if (Array.isArray(value)) {