diff --git a/CHANGELOG.md b/CHANGELOG.md index c5116c8..ce36ec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,24 @@ # Changelog -## 0.3.2 2024-01 +## 0.3.5 2024-03 + +## 0.3.4 2024-02-20 + +* [Add plugin event bus `click-flashcard-action`](https://github.com/siyuan-note/siyuan/issues/10318) + +## 0.3.3 2024-01-24 + +* Update dock icon class + +## 0.3.2 2024-01-09 + +* [Add plugin `protyleOptions`](https://github.com/siyuan-note/siyuan/issues/10090) +* [Add plugin api `uninstall`](https://github.com/siyuan-note/siyuan/issues/10063) +* [Add plugin method `updateCards`](https://github.com/siyuan-note/siyuan/issues/10065) +* [Add plugin function `lockScreen`](https://github.com/siyuan-note/siyuan/issues/10063) +* [Add plugin event bus `lock-screen`](https://github.com/siyuan-note/siyuan/pull/9967) +* [Add plugin event bus `open-menu-inbox`](https://github.com/siyuan-note/siyuan/pull/9967) + ## 0.3.1 2023-12-06 diff --git a/README.md b/README.md index 1f4ea7a..981ca43 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [中文版](./README_zh_CN.md) -> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.2](https://github.com/siyuan-note/plugin-sample/tree/v0.3.2) +> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.4](https://github.com/siyuan-note/plugin-sample/tree/v0.3.4) @@ -233,3 +233,56 @@ If you insist on removing all svelte dependencies so that they do not pollute yo - Line 20: `svelte(),` 4. delete line 37 of `tsconfig.json` from `"svelte"` 5. 5. re-run `pnpm i` + +## Developer's Guide + +Developers of SiYuan need to pay attention to the following specifications. + +### 1. File Reading and Writing Specifications + +If plugins or external extensions require direct reading or writing of files under the `data` directory, please use the kernel API to achieve this. **Do not call `fs` or other electron or nodejs APIs directly**, as it may result in data loss during synchronization and cause damage to cloud data. + +Related APIs can be found at: `/api/file/*` (e.g., `/api/file/getFile`). + +### 2. Daily Note Attribute Specifications + +When creating a diary in SiYuan, a custom-dailynote-yyyymmdd attribute will be automatically added to the document to distinguish it from regular documents. + +> For more details, please refer to [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807). + +Developers should pay attention to the following when developing the functionality to manually create Daily Notes: + +- If `/api/filetree/createDailyNote` is called to create a diary, the attribute will be automatically added to the document, and developers do not need to handle it separately. +- If a document is created manually by developer's code (e.g., using the `createDocWithMd` API to create a diary), please manually add this attribute to the document. + +Here is a reference code: + +```ts +/* + * Copyright (c) 2023 by frostime. All Rights Reserved. + * @Author : frostime + * @Url : https://github.com/frostime/siyuan-dailynote-today/blob/v1.3.0/src/func/dailynote/dn-attr.ts + */ + +export function formatDate(date?: Date, sep=''): string { + date = date === undefined ? new Date() : date; + let year = date.getFullYear(); + let month = date.getMonth() + 1; + let day = date.getDate(); + return `${year}${sep}${month < 10 ? '0' + month : month}${sep}${day < 10 ? '0' + day : day}`; +} + +/** + * Set custom attribute: `custom-dailynote-yyyyMMdd`: yyyyMMdd + * https://github.com/siyuan-note/siyuan/issues/9807 + * @param doc_id Id of daily note + */ +export function setCustomDNAttr(doc_id: string, date?: Date) { + let td = formatDate(date); + let attr = `custom-dailynote-${td}`; + // 构建 attr: td + let attrs: { [key: string]: string } = {}; + attrs[attr] = td; + serverApi.setBlockAttrs(doc_id, attrs); +} +``` diff --git a/README_zh_CN.md b/README_zh_CN.md index a0f9538..b2d3ad3 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -4,7 +4,7 @@ [English](./README.md) -> 本例同 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.2](https://github.com/siyuan-note/plugin-sample/tree/v0.3.2) +> 本例同 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.4](https://github.com/siyuan-note/plugin-sample/tree/v0.3.4) 1. 使用 vite 打包 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 @@ -224,3 +224,57 @@ PR 社区集市仓库。 - 第二十行: `svelte(),` 4. 删掉 `tsconfig.json` 中 37 行 `"svelte"` 5. 重新执行 `pnpm i` + + +## 开发者须知 + +思源开发者需注意以下规范。 + +### 1. 读写文件规范 + +插件或者外部扩展如果有直接读取或者写入 data 下文件的需求,请通过调用内核 API 来实现,**不要自行调用 `fs` 或者其他 electron、nodejs API**,否则可能会导致数据同步时分块丢失,造成云端数据损坏。 + +相关 API 见: `/api/file/*`(例如 `/api/file/getFile` 等)。 + +### 2. Daily Note 属性规范 + +思源在创建日记的时候会自动为文档添加 custom-dailynote-yyyymmdd 属性, 以方便将日记文档同普通文档区分。 + +> 详情请见 [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807)。 + +开发者在开发手动创建 Daily Note 的功能时请注意: + +- 如果调用了 `/api/filetree/createDailyNote` 创建日记,那么文档会自动添加这个属性,无需开发者特别处理。 +- 如果是开发者代码手动创建文档(例如使用 `createDocWithMd` API 创建日记),请手动为文档添加该属性。 + +参考代码: + +```ts +/* + * Copyright (c) 2023 by frostime. All Rights Reserved. + * @Author : frostime + * @Url : https://github.com/frostime/siyuan-dailynote-today/blob/v1.3.0/src/func/dailynote/dn-attr.ts + */ + +export function formatDate(date?: Date, sep=''): string { + date = date === undefined ? new Date() : date; + let year = date.getFullYear(); + let month = date.getMonth() + 1; + let day = date.getDate(); + return `${year}${sep}${month < 10 ? '0' + month : month}${sep}${day < 10 ? '0' + day : day}`; +} + +/** + * Set custom attribute: `custom-dailynote-yyyyMMdd`: yyyyMMdd + * https://github.com/siyuan-note/siyuan/issues/9807 + * @param doc_id Id of daily note + */ +export function setCustomDNAttr(doc_id: string, date?: Date) { + let td = formatDate(date); + let attr = `custom-dailynote-${td}`; + // 构建 attr: td + let attrs: { [key: string]: string } = {}; + attrs[attr] = td; + serverApi.setBlockAttrs(doc_id, attrs); +} +``` diff --git a/public/icon.png b/icon.png similarity index 100% rename from public/icon.png rename to icon.png diff --git a/package.json b/package.json index ed76517..24108a9 100644 --- a/package.json +++ b/package.json @@ -13,20 +13,20 @@ "build": "vite build" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^2.0.3", + "@sveltejs/vite-plugin-svelte": "^2.4.1", "@tsconfig/svelte": "^4.0.1", - "@types/node": "^20.2.0", + "@types/node": "^20.3.0", "eslint": "^8.42.0", "fast-glob": "^3.2.12", "glob": "^7.2.3", "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", - "sass": "^1.62.1", - "siyuan": "0.9.2", - "svelte": "^3.57.0", + "sass": "^1.63.3", + "siyuan": "0.9.4", + "svelte": "^3.59.1", "ts-node": "^10.9.1", - "typescript": "^5.0.4", - "vite": "^4.3.7", + "typescript": "^5.1.3", + "vite": "^4.5.2", "vite-plugin-static-copy": "^0.15.0", "vite-plugin-zip-pack": "^1.0.5" } diff --git a/plugin.json b/plugin.json index c9be70d..b810268 100644 --- a/plugin.json +++ b/plugin.json @@ -2,8 +2,8 @@ "name": "plugin-sample-vite-svelte", "author": "frostime", "url": "https://github.com/siyuan-note/plugin-sample-vite-svelte", - "version": "0.3.2", - "minAppVersion": "2.12.1", + "version": "0.3.4", + "minAppVersion": "3.0.0", "backends": [ "windows", "linux", diff --git a/public/preview.png b/preview.png similarity index 100% rename from public/preview.png rename to preview.png diff --git a/src/index.ts b/src/index.ts index 227b09e..b950a7b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,6 +120,7 @@ export default class PluginSample extends Plugin { size: { width: 200, height: 0 }, icon: "iconSaving", title: "Custom Dock", + hotkey: "⌥⌘W", }, data: { text: "This is my custom dock" @@ -145,11 +146,11 @@ export default class PluginSample extends Plugin { dock.element.innerHTML = `