Fixed tags bug

This commit is contained in:
chris
2023-01-01 11:44:18 +08:00
parent 517426ea7a
commit 1887ad8f3d
2 changed files with 22 additions and 9 deletions

View File

@@ -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开关",
},
}

27
main.ts
View File

@@ -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)")