chore: allow tags to be overwritten by md header template

Revert "add: auto-sync tags"

This reverts commit 2d5b78f648.
This commit is contained in:
windingwind 2024-07-11 11:05:57 +08:00
parent 79a761e05b
commit 156c145715
12 changed files with 16 additions and 67 deletions

View File

@ -71,11 +71,6 @@
preference="__prefsPrefix__.syncAttachmentFolder"
></html:input>
</hbox>
<checkbox
data-l10n-id="sync-updateTags"
native="true"
preference="__prefsPrefix__.sync.updateTags"
/>
<hbox align="center">
<button
onclick="Zotero.__addonInstance__.hooks.onShowSyncManager()"

View File

@ -16,10 +16,6 @@ sync-period-label = Auto-sync period (seconds)
sync-attachmentFolder-label = Attachment folder
sync-manager =
.label = Open Sync Manager
sync-updateTags =
.label = Always update tags
.tooltiptext = Keep note tags in sync with tags in YAML header of the markdown file
template-title = Template
template-editor =
.label = Open Template Editor

View File

@ -16,10 +16,6 @@ sync-period-label = Intervallo della sincronizzazione automatica (secondi)
sync-attachmentFolder-label = Cartella degli allegati
sync-manager =
.label = Apri Manager di sincronizzazione
sync-updateTags =
.label = Aggiorna sempre i tag
.tooltiptext = Keep note tags in sync with tags in YAML header of the markdown file
template-title = Template
template-editor =
.label = Apri Editor dei template

View File

@ -16,10 +16,6 @@ sync-period-label = Авто-синк период (сек)
sync-attachmentFolder-label = Attachment folder
sync-manager =
.label = Открыть Синк менеджер
sync-updateTags =
.label = Всегда обновлять теги
.tooltiptext = Keep note tags in sync with tags in YAML header of the markdown file
template-title = Шаблон
template-editor =
.label = Открыть редактор шаблонов

View File

@ -16,10 +16,6 @@ sync-period-label = Oto-Senkronize aralığı (saniye)
sync-attachmentFolder-label = Ek Klasörü
sync-manager =
.label = Senkronizasyon Yönetimini Aç
sync-updateTags =
.label = Her zaman etiketleri güncelle
.tooltiptext = Keep note tags in sync with tags in YAML header of the markdown file
template-title = Şablon
template-editor =
.label = Şablon Düzenleyiciyi Aç

View File

@ -16,10 +16,6 @@ sync-period-label = 自动同步周期 (秒)
sync-attachmentFolder-label = 附件文件夹
sync-manager =
.label = 打开同步管理器
sync-updateTags =
.label = 总是更新标签
.tooltiptext = 保持笔记标签与 markdown 的 YAML 头标签同步
template-title = 模板
template-editor =
.label = 打开模板编辑器

View File

@ -1,7 +1,6 @@
pref("__prefsPrefix__.syncNoteIds", "");
pref("__prefsPrefix__.syncPeriodSeconds", 30);
pref("__prefsPrefix__.syncAttachmentFolder", "attachments");
pref("__prefsPrefix__.sync.updateTags", false);
pref("__prefsPrefix__.autoAnnotation", false);

View File

@ -1,6 +1,5 @@
import { addLineToNote } from "../../utils/note";
import { config } from "../../../package.json";
import { getPref } from "../../utils/prefs";
export async function fromMD(
filepath: string,
@ -68,15 +67,5 @@ export async function fromMD(
},
});
}
if (getPref("sync.updateTags")) {
const tags = mdStatus.meta?.tags || [];
noteItem.setTags(tags);
await noteItem.saveTx({
notifierData: {
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY,
},
});
}
return noteItem;
}

View File

@ -246,18 +246,19 @@ async function doCompare(
} else if (MDAhead) {
return SyncCode.MDAhead;
} else {
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;
}
// 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;
}
}

View File

@ -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 = `<pre>${YAML.stringify(header, 10)}</pre>`;
}
} else if (templateName.includes("ExportMDFileContent")) {

View File

@ -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;
}
}

1
typings/note.d.ts vendored
View File

@ -28,7 +28,6 @@ declare interface MDStatus {
$version: number;
$libraryID?: number;
$itemKey?: string;
tags?: string[];
} | null;
content: string;
filedir: string;