From 156c145715e8a15d17672af471b79aea0e5f9e1b Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:05:57 +0800 Subject: [PATCH] chore: allow tags to be overwritten by md header template Revert "add: auto-sync tags" This reverts commit 2d5b78f648b13dfc319717db2bed4afed06bf596. --- addon/chrome/content/preferences.xhtml | 5 ----- addon/locale/en-US/preferences.ftl | 4 ---- addon/locale/it-IT/preferences.ftl | 4 ---- addon/locale/ru-RU/preferences.ftl | 4 ---- addon/locale/tr-TR/preferences.ftl | 4 ---- addon/locale/zh-CN/preferences.ftl | 4 ---- addon/prefs.js | 1 - src/modules/import/markdown.ts | 11 ----------- src/modules/sync/hooks.ts | 25 +++++++++++++------------ src/modules/template/preview.ts | 7 ------- src/utils/convert.ts | 13 +++---------- typings/note.d.ts | 1 - 12 files changed, 16 insertions(+), 67 deletions(-) diff --git a/addon/chrome/content/preferences.xhtml b/addon/chrome/content/preferences.xhtml index acfdca2..5b0bd95 100644 --- a/addon/chrome/content/preferences.xhtml +++ b/addon/chrome/content/preferences.xhtml @@ -71,11 +71,6 @@ preference="__prefsPrefix__.syncAttachmentFolder" > - - maxLastModifiedPeriod - ) { - return SyncCode.MDAhead; - } else { - return SyncCode.UpToDate; - } + // const maxLastModifiedPeriod = 3000; + // if ( + // mdStatus.lastmodify && + // syncStatus.lastsync && + // // If the file is modified after the last sync, it's ahead + // Math.abs(mdStatus.lastmodify.getTime() - syncStatus.lastsync) > + // maxLastModifiedPeriod + // ) { + // return SyncCode.MDAhead; + // } else { + // return SyncCode.UpToDate; + // } + return SyncCode.UpToDate; } } diff --git a/src/modules/template/preview.ts b/src/modules/template/preview.ts index bae8809..d5a0440 100644 --- a/src/modules/template/preview.ts +++ b/src/modules/template/preview.ts @@ -1,6 +1,5 @@ import YAML = require("yamljs"); import { getNoteLink } from "../../utils/link"; -import { getPref } from "../../utils/prefs"; export { renderTemplatePreview }; @@ -56,12 +55,6 @@ async function renderTemplatePreview( libraryID: data.libraryID, itemKey: data.key, }); - if (getPref("sync.updateTags")) { - const tags = data.getTags(); - if (tags.length) { - header.tags = tags.map((tag) => tag.tag); - } - } html = `${YAML.stringify(header, 10)}`; } } else if (templateName.includes("ExportMDFileContent")) { diff --git a/src/utils/convert.ts b/src/utils/convert.ts index 8ad1033..531b182 100644 --- a/src/utils/convert.ts +++ b/src/utils/convert.ts @@ -110,7 +110,7 @@ async function note2md( ); const cachedHeader = options.cachedYAMLHeader || {}; for (const key in cachedHeader) { - if (key.startsWith("$") && key in header) { + if ((key === "tags" || key.startsWith("$")) && key in header) { // generated header overwrites cached header continue; } else { @@ -126,13 +126,6 @@ async function note2md( $libraryID: noteItem.libraryID, $itemKey: noteItem.key, }); - if (getPref("sync.updateTags")) { - const tags = noteItem.getTags(); - header.tags = []; - if (tags.length) { - tags.forEach((tag) => header.tags.push(tag.tag)); - } - } const yamlFrontMatter = `---\n${YAML.stringify(header, 10)}\n---`; md = `${yamlFrontMatter}\n${md}`; } @@ -199,7 +192,7 @@ async function link2html( usePosition?: boolean; } = {}, ) { - ztoolkit.log("link2html", link); + ztoolkit.log("link2html", link, options); const linkParams = getNoteLinkParams(link); if (!linkParams.noteItem) { return ""; @@ -1230,7 +1223,7 @@ async function processM2NRehypeImageNodes( src = jointPath(fileDir, src); } if (!(await fileExists(src))) { - ztoolkit.log("parse image, path invalid", src.slice(0, 50)); + ztoolkit.log("parse image, path invalid", src); continue; } } diff --git a/typings/note.d.ts b/typings/note.d.ts index 9906825..5ecf81c 100644 --- a/typings/note.d.ts +++ b/typings/note.d.ts @@ -28,7 +28,6 @@ declare interface MDStatus { $version: number; $libraryID?: number; $itemKey?: string; - tags?: string[]; } | null; content: string; filedir: string;
${YAML.stringify(header, 10)}