From 1887ad8f3d2b19b2691e9d470e92087b63656efb Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 1 Jan 2023 11:44:18 +0800 Subject: [PATCH] Fixed tags bug --- Message.ts | 4 +++- main.ts | 27 +++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Message.ts b/Message.ts index 4bb7791..b9b1514 100644 --- a/Message.ts +++ b/Message.ts @@ -6,12 +6,14 @@ export const NoticeMsg: {[key: string]:any} = { "open-notion": "Please open the file that needs to be synchronized", "config-secrets-notion-api": "Please set up the notion API in the settings tab.", "config-secrets-database-id": "Please set up the database id in the settings tab.", + "set-tags-fail": "Set tags fail,please check the frontmatter of the file or close the tag switch in the settings tab.", }, "zh": { "notion-logo": "分享到Notion", "sync-success": "同步到Notion成功:\n", "sync-fail": "同步到Notion失败: \n", - "open-file": "请打开需要同步的文件" + "open-file": "请打开需要同步的文件", + "set-tags-fail": "设置标签失败,请检查文件的frontmatter,或者在插件设置中关闭设置tags开关", }, } diff --git a/main.ts b/main.ts index 40bc422..552cf61 100644 --- a/main.ts +++ b/main.ts @@ -12,6 +12,7 @@ import { import {addIcons} from 'icon'; import { Upload2Notion } from "Upload2Notion"; import {NoticeMConfig} from "Message"; +import { CLIENT_RENEG_LIMIT } from "tls"; // Remember to rename these classes and interfaces! @@ -79,8 +80,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { ); return; } - const { markDownData, nowFile, tags } = - await this.getNowFileMarkdownContent(this.app); + const { markDownData, nowFile, tags } =await this.getNowFileMarkdownContent(this.app); if (markDownData) { @@ -90,7 +90,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { if(res.status === 200){ new Notice(`${langConfig["sync-success"]}${basename}`) }else { - new Notice(`${langConfig["sync-fail"]}${basename}`, 3000) + new Notice(`${langConfig["sync-fail"]}${basename}`, 5000) } } } @@ -99,8 +99,19 @@ export default class ObsidianSyncNotionPlugin extends Plugin { const nowFile = app.workspace.getActiveFile(); const { allowTags } = this.settings; let tags = [] - if (app.metadataCache.getFileCache(nowFile).tags !== undefined && allowTags) { - tags = app.metadataCache.getFileCache(nowFile).frontmatter.tags; + let fileTags = app.metadataCache.getFileCache(nowFile)?.frontmatter?.tags; + console.log(nowFile, fileTags) + console.log(app.metadataCache.getFileCache(nowFile)) + if(allowTags && !fileTags) { + new Notice(langConfig["set-tags-fail"]); + return + } + try { + if (app.metadataCache.getFileCache(nowFile).tags !== undefined && allowTags) { + tags = app.metadataCache.getFileCache(nowFile).frontmatter.tags; + } + } catch (error) { + new Notice(langConfig["set-tags-fail"]); } if (nowFile) { const markDownData = await nowFile.vault.read(nowFile); @@ -156,7 +167,7 @@ class SampleSettingTab extends PluginSettingTab { this.plugin.settings.notionAPI = value; await this.plugin.saveSettings(); }) - t.inputEl.type = 'password' + // t.inputEl.type = 'password' return t }); @@ -172,13 +183,13 @@ class SampleSettingTab extends PluginSettingTab { this.plugin.settings.databaseID = value; await this.plugin.saveSettings(); }) - t.inputEl.type = 'password' + // t.inputEl.type = 'password' return t } ); - notionDatabaseID.controlEl.querySelector('input').type='password' + // notionDatabaseID.controlEl.querySelector('input').type='password' new Setting(containerEl) .setName("Banner url(optional)")