Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Dec 9, 2023
2 parents a00ff6d + 0f40d8e commit ba33ed7
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 166 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### [2023-12-09] v1.3.1: 允许用户在同步后创建日记

- 允许用户在同步后创建日记
- 优化对话框显示


### [2023-12-05] v1.3.0: 为日记增添自定义属性

1. 插件自己创建日记的时候, 同样也会添加对应的属性
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ order by A.value desc;

问题的原因是在思源的架构中,**插件的启动运行在开机数据同步之前**。假如你此前在 A 设备上创建了日记,然后在打开 B 设备的时候,插件会自动给你创建一份日记;然后思源才会同步数据,这样依赖之前在 A 上创建的日记和现在在 B 上创建的日记就重复了。

有两种解决方案:

1. 手动合并日记
2. 开启设置中的 「日记-同步后再创建日记」选项,注意这是一个实验性功能,请斟酌使用



### Q: 下拉框是选择默认打开的笔记本的吗?
Expand Down
5 changes: 5 additions & 0 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ The conditions for this issue to occur are:

The reason for this problem is that in the architecture of SiYuan, **the plugin's initialization runs before the data synchronization during startup**. If you previously created a daily note on Device A and then open Device B, the plugin will automatically create another daily note for you. Only after that, Obsidian will synchronize the data, resulting in duplicate daily notes, one from the previous creation on Device A and another from the current creation on Device B.

There are two solutions:

1. Manually merge the diaries.
2. Enable the "Daily Note - Auto create DN only after synchronization" option in the settings. Please note that this is an experimental feature, so use it with caution.

### Q: Is the dropdown box used for selecting the default notebook?

> - **Note: Don't misunderstand**, this drop-down box is not for selecting the default notebook, but for opening the diary quickly!
Expand Down
5 changes: 5 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ order by A.value desc;

问题的原因是在思源的架构中,**插件的启动运行在开机数据同步之前**。假如你此前在 A 设备上创建了日记,然后在打开 B 设备的时候,插件会自动给你创建一份日记;然后思源才会同步数据,这样依赖之前在 A 上创建的日记和现在在 B 上创建的日记就重复了。

有两种解决方案:

1. 手动合并日记
2. 开启设置中的 「日记-同步后再创建日记」选项,注意这是一个实验性功能,请斟酌使用



### Q: 下拉框是选择默认打开的笔记本的吗?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"sass": "^1.62.1",
"siyuan": "^0.8.9",
"siyuan": "^0.9.0",
"svelte": "^3.57.0",
"sy-plugin-changelog": "^0.0.7",
"ts-node": "^10.9.1",
Expand Down
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.3.0",
"version": "1.3.1",
"minAppVersion": "2.11.1",
"description": {
"zh_CN": "自动创建日记 + 快速打开日记 + 日程 TODO 管理 + 移动块功能",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/components/gutter-menu.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { i18n } from "../utils";
import { i18n } from "@/utils";
import { EventBus, Menu } from "siyuan";
import { iconDiary } from "./svg";
import { settings } from "../global-status";
import { reserveBlock, dereserveBlock } from "./libs/reserve";
import { createMenuItems } from "./libs/move";
import { settings } from "@/global-status";
import { reserveBlock, dereserveBlock } from "@/func/reserve";
import { createMenuItems } from "@/func/move";

let blockGutterClickEvent: EventListener;
let docGutterClickEvent: EventListener;
Expand Down
47 changes: 35 additions & 12 deletions src/components/set-past-dn-attr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/*
* Copyright (c) 2023 by frostime. All Rights Reserved.
* @Author : frostime
* @Date : 2023-12-04 18:48:59
* @FilePath : /src/components/set-past-dn-attr.ts
* @LastEditTime : 2023-12-09 19:51:05
* @Description :
*/
import { Dialog } from "siyuan";
import {searchAndSearchAllDNAttr} from '@/func';
import { searchAndSetAllDNAttr, findoutEarliestDN, formatDate } from '@/func';
import notebooks from "@/global-notebooks";

/**
Expand All @@ -10,26 +18,41 @@ export const setDNAttrDialog = async () => {
title: 'Running',
content: `
<div class="b3-dialog__content">
<div id="body" style="padding: 6px 12px;">
<ul id="notebooks">
</ul>
<div id="body" style="padding: 6px 12px; width: 100%;">
<table id="notebooks" cellpadding="10" style="width: 100%;">
<thead>
<tr style="text-align: left;">
<th>Notebook</th>
<th>Start Date</th>
<th>Daily Notes</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>`,
width: "20em",
height: "20em",
width: "50em",
height: "25em",
});
let div: HTMLDivElement = dialog.element.querySelector(".b3-dialog__container");
div.style.maxHeight = "50%";
let ul: HTMLUListElement = dialog.element.querySelector("#body > ul#notebooks");
let table: HTMLTableElement = dialog.element.querySelector("#body > table#notebooks");
for (let notebook of notebooks) {
if (notebook.dailynoteSprig === undefined || notebook.dailynoteSprig === '') {
continue;
}
let li = document.createElement('li');
li.innerHTML = `<b>${notebook.name}...</b>`;
ul.appendChild(li);
let ans = await searchAndSearchAllDNAttr(notebook);
li.innerHTML = `<b>${notebook.name}</b>: <b>${ans?.length ?? 0}</b> daily notes.`;
let start: Date = await findoutEarliestDN(notebook);
let tr: HTMLTableRowElement = document.createElement('tr');
tr.innerHTML = `<tr style="text-align: left;">
<td>${notebook.name}</td>
<td>${formatDate(start, '-')}</td>
<td>...</td>
</tr>`;
table.appendChild(tr);
let ans = await searchAndSetAllDNAttr(notebook, start);
(tr.querySelector('td:nth-child(3)') as HTMLTableCellElement).innerText = `${ans.length}`;
}
let body = dialog.element.querySelector("#body");
let hint = document.createElement('div');
Expand Down
9 changes: 4 additions & 5 deletions src/components/setting-gui.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
},
],
dailynote: [
{
name: "AutoOpenAfterSync",
type: "checkbox"
},
{
name: "DefaultNotebook",
type: "input",
Expand All @@ -57,11 +61,6 @@
name: "SetPastDailyNoteAttr",
type: "button"
}
//1.3.0 版本再加上
// {
// name: "AutoOpenAfterSync",
// type: "checkbox"
// }
],
reservation: [
{
Expand Down
28 changes: 1 addition & 27 deletions src/func/dailynote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,11 @@
* @Author : Yp Z
* @Date : 2023-06-16 21:00:30
* @FilePath : /src/func/dailynote/index.ts
* @LastEditTime : 2023-12-03 12:09:06
* @LastEditTime : 2023-12-09 18:12:38
* @Description :
*/
import { settings } from '@/global-status';

import type DailyNoteTodayPlugin from '@/index';
export * from './basic';
export * from './open-dn';
export * from './handle-duplicate';
export * from './dn-attr';
export * from './past-dn';

//@ts-ignore
const SYNC_ENABLED = window.siyuan.config.sync.enabled;

export class AutoOpenDailyNoteHandler {
plugin: DailyNoteTodayPlugin;
openOnStart: boolean;
autoOpenAfterSync: boolean;

constructor(plugin: DailyNoteTodayPlugin) {
this.plugin = plugin;
this.openOnStart = settings.get('OpenOnStart');
this.autoOpenAfterSync = settings.get('AutoOpenAfterSync');
}

onPluginLoad() {
//如果思源没有开启
if (SYNC_ENABLED === false) {

}
}
}

24 changes: 17 additions & 7 deletions src/func/dailynote/past-dn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@ export async function searchDailyNotesBetween(notebook: Notebook, begin: Date, e
}


/**
* 查询、遍历之前所有的日记, 并为每个日记设置自定义属性 custom-dailynote-yyyyMMdd
* @param notebook
*/
export async function searchAndSearchAllDNAttr(notebook: Notebook) {
export async function findoutEarliestDN(notebook: Notebook): Promise<Date> {

let dailynoteSprig = notebook?.dailynoteSprig;
if (dailynoteSprig === undefined || dailynoteSprig === null || dailynoteSprig === '') {
return;
return null;
}
if (dailynoteSprig.startsWith('/')) {
dailynoteSprig = dailynoteSprig.substring(1);
Expand All @@ -129,14 +125,28 @@ export async function searchAndSearchAllDNAttr(notebook: Notebook) {
let docs = await api.sql(sql);
if (docs.length === 0) {
console.warn(`未找到日记本 ${notebook.name} 的日记`);
return;
return null;
}
let firstDoc = docs[0];
let created: string = firstDoc.created;
let year = created.substring(0, 4);
let month = created.substring(4, 6);
let day = created.substring(6, 8);
let firstDate = new Date(`${year}-${month}-${day}`);
return firstDate;
}


/**
* 查询、遍历之前所有的日记, 并为每个日记设置自定义属性 custom-dailynote-yyyyMMdd
* @param notebook
*/
export async function searchAndSetAllDNAttr(notebook: Notebook, firstDate?: Date) {

firstDate = firstDate !== undefined ? firstDate : await findoutEarliestDN(notebook);
if (firstDate === null) {
return [];
}

// set custom attr for all past daily notes
let dailynotes = await searchDailyNotesBetween(
Expand Down
Loading

0 comments on commit ba33ed7

Please sign in to comment.