Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Apr 16, 2024
2 parents db6a6c6 + a38cc51 commit a98f5b4
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [2024-04-16] v1.5.1: 自动处理重复日记

- 增加了自动处理重复日记的方案,开启之后将不会再弹出重复日记处理的对话框,而是自动按照预先选择的方案处理重复的日记
- 请在插件设置的「日记-自动处理重复日记方案」中进行配置


### [2024-04-06] v1.5.0: 优化重复日记文档处理方法

- 优化重复日记处理方案,提供多种处理重复日记的方法。
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ order by A.value desc;
- 或者关闭对话框根据提示手动处理
- **每天**对话框只会在启动的时候**运行一次**,关闭后,你就需要自行手动处理

如果你不想每次都手动处理,可以在设置中选择默认的处理方式,这样插件会自动帮你处理重复的日记。

> 默认设置为「手动处理」,即每次都弹出对话框,让用户来选择处理方案。
![](asset/AutoHandle-ZH.png)



## 常见问题

Expand Down
6 changes: 6 additions & 0 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ Duplicate Document Prompt Dialog:
- Alternatively, you can close the dialog and manually handle the duplicates as instructed.
- The dialog will **only run once** when it is launched **each day**. After closing it, you will need to manually handle the duplicates yourself.

If you don't want to handle it manually every time, you can choose the default processing method in the settings. This way, the plugin will automatically handle repetitive entries for you.

> The default setting is "Manually handle," which means a dialog box will pop up every time, allowing the user to choose a processing option.
![](asset/AutoHandle-EN.png)

## FAQ


Expand Down
7 changes: 7 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ order by A.value desc;
- 或者关闭对话框根据提示手动处理
- **每天**对话框只会在启动的时候**运行一次**,关闭后,你就需要自行手动处理

如果你不想每次都手动处理,可以在设置中选择默认的处理方式,这样插件会自动帮你处理重复的日记。

> 默认设置为「手动处理」,即每次都弹出对话框,让用户来选择处理方案。
![](https://gitlab.com/ypz.open/siyuan/siyuan-dailynote-today/-/raw/main/asset/AutoHandle-ZH.png)



## 常见问题

Expand Down
Binary file added asset/AutoHandle-EN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/AutoHandle-ZH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"en_US": "Daily Note Today"
},
"url": "https://github.com/frostime/siyuan-dailynote-today",
"version": "1.5.0",
"version": "1.5.1",
"minAppVersion": "3.0.0",
"description": {
"zh_CN": "自动创建日记 + 快速打开日记 + 日程 TODO 管理 + 移动块功能",
Expand Down
12 changes: 4 additions & 8 deletions src/components/setting-gui.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@
name: "AutoOpenAfterSync",
type: "checkbox"
},
// {
// name: "AutoHandleDuplicate",
// type: "checkbox"
// },
// {
// name: "AutoHandleDuplicateMethod",
// type: "select"
// }
{
name: "AutoHandleDuplicateMethod",
type: "select"
}
],
reservation: [
{
Expand Down
50 changes: 39 additions & 11 deletions src/func/dailynote/handle-duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ type TDuplicateHandler = (main: DocBlock, others: DocBlock[]) => boolean | Promi
* @returns
*/
async function mergeDocs(mergeTo: DocBlock, otherDocs: DocBlock[]): Promise<boolean> {
showMessage("Merging", 1000, "info");

// let childs: Block[] = await serverApi.getChildBlocks(latestDoc.id);
// let lastChildBlockID = childs[childs.length - 1].id;
let result = await serverApi.appendBlock(mergeTo.id, i18n.ConflictDiary.HeadingMarkdown, "markdown");
let lastChildBlockID = result?.[0]?.doOperations[0].id;
if (lastChildBlockID === undefined) {
console.error(`无法获取最新日记的最后一个 block id`);
// showMessage(i18n.ConflictDiary.fail, 2000, "error");
// dialog.destroy();
return false;
}

Expand All @@ -39,7 +36,6 @@ async function mergeDocs(mergeTo: DocBlock, otherDocs: DocBlock[]): Promise<bool
await serverApi.doc2Heading(id, lastChildBlockID, true);
console.debug(`Merge doc ${id}`);
}
// dialog.destroy();
return true;
}

Expand All @@ -50,29 +46,24 @@ async function mergeDocs(mergeTo: DocBlock, otherDocs: DocBlock[]): Promise<bool
* @returns
*/
async function deleteDocs(main: DocBlock, others: DocBlock[]): Promise<boolean> {
showMessage("Deleting", 1000, "info");
let allPromise = [];
for (let doc of others) {
allPromise.push(serverApi.removeDoc(doc.box, doc.path));
console.debug(`Remove doc ${doc.id}`);
}
await Promise.all(allPromise);
// dialog.destroy();
return true;
}

/**
* 智能合并
*/
async function smartMergeDocs(main: DocBlock, others: DocBlock[]): Promise<boolean> {
showMessage("Smart Merging", 1000, "info");

let result = await serverApi.appendBlock(main.id, i18n.ConflictDiary.HeadingMarkdown, "markdown");
let lastChildBlockID = result?.[0]?.doOperations[0].id;
if (lastChildBlockID === undefined) {
console.error(`无法获取最新日记的最后一个 block id`);
// showMessage(i18n.ConflictDiary.fail, 2000, "error");
// dialog.destroy();
return false;
}

Expand Down Expand Up @@ -268,12 +259,16 @@ const handleDuplicateDiary = async (docs: DocBlock[], method?: TDuplicateHandleM
console.error(`No such method: ${method}`);
return false;
});
const msg = i18n.ConflictDiary.CompleteMsg?.[method];
if (msg) {
showMessage(msg, 5000, "info");
}
let flag = await handler(earliestDoc, docs);

if (flag) {
showMessage(i18n.ConflictDiary.success, 2000, "info");
showMessage(i18n.ConflictDiary.success, 5000, "info");
} else {
showMessage(i18n.ConflictDiary.fail, 2000, "error");
showMessage(i18n.ConflictDiary.fail, 5000, "error");
}
}

Expand Down Expand Up @@ -317,6 +312,13 @@ export async function checkDuplicateDiary(): Promise<boolean> {

// ==================== 合并今天的日记 ====================
console.warn(`Conflict daily note: ${notebook.name} ${hpath}`);

const method: TDuplicateHandleMethod = settings.get('AutoHandleDuplicateMethod');
if (method !== 'None') {
await handleDuplicateDiary(docs, method);
return true;
}

const html = buildShowDuplicateDocDom(docs, notebook, ascendantDiff);
let dialog = new Dialog({
title: i18n.Name,
Expand All @@ -341,3 +343,29 @@ export async function checkDuplicateDiary(): Promise<boolean> {
return true;
}


//TODO: 测试用,记得删除
const addTestBtn = () => {
let btn = document.createElement('button');
Object.assign(btn.style, {
position: 'fixed',
bottom: '50px',
right: '50px',
zIndex: '1000',
});
btn.classList.add('b3-button', 'b3-button--primary');
btn.innerText = '检查重复日记';
btn.onclick = async () => {
let flag = await checkDuplicateDiary();
if (flag) {
showMessage('Debug: 有重复日记');
} else {
showMessage('Debug: 没有重复日记');
}
};
document.body.appendChild(btn);
}

if (process.env.DEV_MODE === "true") {
addTestBtn();
}
3 changes: 1 addition & 2 deletions src/global-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class SettingManager {
RetvType: 'embed' as RetvType, //Retrieved 块的类型
NotebookBlacklist: {}, //笔记本黑名单
HighlightResv: true as boolean, //高亮显示预约块
AutoHandleDuplicate: false, // 是否自动处理重复日记
AutoHandleDuplicateMethod: 'AllMerge' as TDuplicateHandleMethod // 自动处理重复日记的方法
AutoHandleDuplicateMethod: 'None' as TDuplicateHandleMethod // 自动处理重复日记的方法
};

constructor() {
Expand Down
22 changes: 7 additions & 15 deletions src/i18n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
## V1.5.0 重复日记处理 | Duplicate daily note handling
## V1.5.1 自动处理重复日记 | Auto-handle duplicate daily notes

> **注意: 本次更新对「重复日记自动处理」改动较大,建议去阅读一下插件文档 {## 特殊问题 | 重复的日记}**
- 增加了自动处理重复日记的方案,开启之后将不会再弹出重复日记处理的对话框,而是自动按照预先选择的方案处理重复的日记
- 请在插件设置的「日记-自动处理重复日记方案」中进行配置

优化重复日记处理方案,提供多种处理重复日记的方法。

1. 全部合并(此前的默认行为):将所有日记合并到最早的那个日记中
2. 删除日记:将除了最早创建的日记以外的日记文档全部删除
3. 智能合并:将非空、经过更改、存在引用的日记合并到最早的那个日记中,删除空白且无引用的日记文档
4. 垃圾箱:将重复的日记移动到 `[daily note root]/trash-bin/` 目录下,并删除 `custom-dailynote-` 属性
> ****: 插件可能会在后续某次更新中<span style="color: var(--b3-theme-primary); font-weight: bold;">移除 「同步后再创建日记」 的功能(因为实测下来发现没什么用)</span>,如果你有什么建议或者想要保留这个功能,请在 issue 中提出。
---

> **Note: This update has made significant changes to the "automatic handling of duplicate DailyNotes". It is recommended to read the plugin documentation {## Special Issues | Duplicate DailyNotes}.**
Optimizing the solution for handling repeated daily notes, multiple methods are provided to address duplicate entries.
- Added an auto-handle duplicates' method, which, when enabled, will no longer prompt a dialog for handling duplicate notes. Instead, it will automatically process duplicate notes according to the pre-selected method.
- Please configure it in the "Diary - Auto-handle duplicates' method" section inside the plugin settings.

1. Merge All (Default Behavior Before): Merge all the notes into the earliest one.
2. Delete Documents: Delete all the daily note documents except the earliest created one.
3. Smart Merge: Merge non-empty, modified, and referenced notes into the earliest one, and delete blank and non-referenced notes.
4. Trash Bin: Move duplicate daily notes to the `[daily note root]/trash-bin/` directory and remove the `custom-dailynote-` attribute.
> **Note**: The plugin may <span style="color: var(--b3-theme-primary); font-weight: bold;">remove the "Auto create DN only after synchronization" feature in the future update (because it is found to be useless in practice)</span>. If you have any suggestions or want to keep this feature, please raise an issue.
16 changes: 10 additions & 6 deletions src/i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ Setting:
text:
Highlight reservation icon in dock bar when there is a reservation on the
day
AutoHandleDuplicate:
title: Auto-handle duplicates
text:
Automatically handel with duplicate daily notes while detected, without
popup dialog
AutoHandleDuplicateMethod:
title: Auto-handle duplicates' method
text: When detected duplicate daily notes, how to handle with them
text: |-
Automatically handel with duplicate daily notes while detected, without popup dialog<br/>
Default: Popup dialog and let user manually choose the method.<br/>
<b>If not 'Manually handle'</b>, auto-handle with the duplicate daily notes with the selected method.
options:
None: Manually handle
AllMerge: Merge all
TrashDup: Move to trash
SmartMerge: Merge smartly
Expand Down Expand Up @@ -194,6 +193,11 @@ ConflictDiary:
HeadingMarkdown: "# Duplicate diaries are listed below"
success: Success
fail: Fail due to unknown reason, please merge them manually
CompleteMsg:
AllMerge: All duplicate diaries have been merged into the main diary
TrashDup: Duplicate diaries have been moved to the trash bin
SmartMerge: Duplicate diaries have been smartly merged into the main diary
DeleteDup: All duplicate diaries have been deleted
DockReserve:
arial: Daily Note Today Reservations
title: Reservations
Expand Down
16 changes: 11 additions & 5 deletions src/i18n/zh_CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ Setting:
HighlightResv:
title: 高亮当日预约
text: 如果当日存在预约,则高亮预约列表的侧边栏图标
AutoHandleDuplicate:
title: 自动处理重复日记
text: 当检测到重复的日记时,不弹出提示框直接自动处理
AutoHandleDuplicateMethod:
title: 自动处理重复日记的方式
text: 当检测到重复的日记时,自动处理的方式
title: 自动处理重复日记方案
text: |-
当检测到重复的日记时,不弹出合并对话框,而是直接指定某个默认处理方案自动处理<br/>
默认选项为:不进行任何处理,即弹出对话框由用户手动处理<br/>
当前选择<b>除了「手动处理」之外</b>的选项时,在检测到重复日记的时候将采用指定的处理方案自动处理
options:
None: 手动处理
AllMerge: 全部合并
TrashDup: 移动到回收站
SmartMerge: 智能合并
Expand Down Expand Up @@ -151,6 +152,11 @@ ConflictDiary:
HeadingMarkdown: "# 以下为其他重复的日记"
success: 自动处理成功
fail: 由于未知原因, 自动处理失败, 请手动处理
CompleteMsg:
AllMerge: 将重复日记全部合并到主日记中
TrashDup: 将重复的日记移动到回收站
SmartMerge: 将重复日记智能合并到主日记中
DeleteDup: 删除了所有重复的日记
DockReserve:
arial: 今日笔记预约
title: 预约
Expand Down
5 changes: 3 additions & 2 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Window {
ws: any;
languages: any;
};
Lute: any;
}


Expand All @@ -21,7 +22,7 @@ type ParentID = BlockId | DocumentId;

type markdown = string;

type TDuplicateHandleMethod = 'DeleteDup' | 'AllMerge' | 'SmartMerge' | 'TrashDup';
type TDuplicateHandleMethod = 'DeleteDup' | 'AllMerge' | 'SmartMerge' | 'TrashDup' | 'None';

type ResvBlock = Block;
type ResvBlockIds = BlockId[];
Expand Down Expand Up @@ -109,7 +110,7 @@ type SettingKey = (
"ExpandGutterMenu" | 'PopupReserveDialog' | 'ResvEmbedAt' |
'RetvType' | 'EnableResvDock' | 'DisableAutoCreateOnMobile' |
'NotebookBlacklist' | 'AutoOpenAfterSync' | 'HighlightResv' |
'AutoHandleDuplicate' | 'AutoHandleDuplicateMethod'
'AutoHandleDuplicateMethod'
);

interface ISettingItem {
Expand Down

0 comments on commit a98f5b4

Please sign in to comment.