diff --git a/src/func/dailynote/handle-duplicate.ts b/src/func/dailynote/handle-duplicate.ts index 789eb9c..13d48ae 100644 --- a/src/func/dailynote/handle-duplicate.ts +++ b/src/func/dailynote/handle-duplicate.ts @@ -41,7 +41,7 @@ async function mergeDocs(docs: DocBlock[], callback?: () => void) { return latestDoc; } -function buildShowDuplicateDocDom(docs: Block[], notebook: Notebook): string { +function buildShowDuplicateDocDom(docs: Block[], notebook: Notebook, ansestorDup?: boolean): string { let confilctTable = []; for (let doc of docs) { @@ -65,6 +65,7 @@ function buildShowDuplicateDocDom(docs: Block[], notebook: Notebook): string { style="margin: 0.5rem;" > ${content} + ${ansestorDup ? i18n.ConflictDiary.part3.join("\n") : ""}
@@ -77,12 +78,31 @@ function buildShowDuplicateDocDom(docs: Block[], notebook: Notebook): string { return html; } +/** + * 检查这些文档是否祖先文档树不同 + */ +function ifAncestorDiff(docs: DocBlock[]): boolean { + let paths: string[] = docs.map(doc => doc.path); + //trim base doc + paths = paths.map(path => path.slice(0, path.lastIndexOf("/"))); + //check if identical + let identical = true; + for (let i = 1; i < paths.length; i++) { + if (paths[i] !== paths[0]) { + identical = false; + break; + } + } + return !identical; +} + /** * 由于同步的问题,默认的笔记本中可能出现重复的日记,这里检查下是否有重复的日记 * @param notebook * @param todayDiaryHpath */ export async function checkDuplicateDiary(): Promise { + // ==================== 检查是否有重复 ==================== let notebook: Notebook = notebooks.default; let hpath = notebook.dailynoteHpath!; let docs = (await getDocsByHpath(hpath, notebook)) as DocBlock[]; @@ -90,7 +110,8 @@ export async function checkDuplicateDiary(): Promise { if (docs.length <= 1) { return false; } - //莫名其妙出现了重复的 id, 所以还是去重一下 + + // ==================== 由于未知原因可能出现重复的 id, 需要去重 ==================== let idSet: Set = new Set(); let uniqueDocs: Array = []; docs.forEach((doc) => { @@ -105,16 +126,24 @@ export async function checkDuplicateDiary(): Promise { return false; } + // ==================== 检查顶部文档树是否也有重复 ==================== + const ascendantDiff = ifAncestorDiff(docs); //如果为 true,说明祖先的文档树也不同 + + // ==================== 合并今天的日记 ==================== console.warn(`Conflict daily note: ${notebook.name} ${hpath}`); - const html = buildShowDuplicateDocDom(docs, notebook); + const html = buildShowDuplicateDocDom(docs, notebook, ascendantDiff); let dialog = new Dialog({ title: i18n.Name, content: html, width: isMobile ? "80%" : "50%", }); - let uniqueDNDoc = null; dialog.element.querySelector("#merge")?.addEventListener("click", async () => { - uniqueDNDoc = mergeDocs(docs, () => { dialog.destroy() }); + mergeDocs(docs, () => { + dialog.destroy(); + if (ascendantDiff) { + showMessage("祖先", 10000, "info"); + } + }); }); return true; } \ No newline at end of file diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 66c9164..eedf958 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -140,6 +140,14 @@ " You may have created a diary on another device before and then created a diary on this device, resulting in a synchronization conflict.", " Please merge and delete redundant diaries manually: Open today's diary, locate the diary document, and the conflicting document will be nearby." ], + "part3": [ + "

", + "We found that in addition to the dailynote document conflict, the parent document at the upper level seems to be in conflict as well, and \"Auto Merge\" cannot handle this complexity of merging document trees.", + "

", + "

", + "Of course, you can still to use the \"Auto Merge\" feature to merge dailynote, but it is recommended that you manually deal with duplicate parent documents after auto-merging.", + "

" + ], "AutoMerge": "Auto merge", "HeadingMarkdown": "# Duplicate diaries are listed below", "success": "Merge success", diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json index 820df4d..ba42b18 100644 --- a/src/i18n/zh_CN.json +++ b/src/i18n/zh_CN.json @@ -142,6 +142,14 @@ "- 应该如何处理?", " 请自行合并删除多余的日记: 打开今日的日记, 然后定位日记文档, 冲突的文档就在一旁" ], + "part3": [ + "

", + "我们发现除了日记文档冲突外,上层的父文档似乎也出现了冲突,「自动合并」无法处理这种合并文档树的复杂情况。", + "

", + "

", + "当然,你可以继续使用「自动合并」功能来合并今日日记的文档,但是建议你在自动合并后手动处理一下重复的父文档。", + "

" + ], "AutoMerge": "自动合并", "HeadingMarkdown": "# 以下为其他重复的日记", "success": "自动合并成功",