Merge branch 'siyuan-note:main' into main
This commit is contained in:
commit
0645799101
9 changed files with 132 additions and 101 deletions
42
README.md
42
README.md
|
@ -65,8 +65,11 @@ complete the following tasks:
|
||||||
* Meta information about the plugin itself, such as plugin description and readme
|
* Meta information about the plugin itself, such as plugin description and readme
|
||||||
* `description` and `readme` fields in plugin.json, and the corresponding README*.md file
|
* `description` and `readme` fields in plugin.json, and the corresponding README*.md file
|
||||||
* Text used in the plugin, such as button text and tooltips
|
* Text used in the plugin, such as button text and tooltips
|
||||||
* src/i18n/*.json language configuration files
|
* public/i18n/*.json language configuration files
|
||||||
* Use `this.i18.key` to get the text in the code
|
* Use `this.i18.key` to get the text in the code
|
||||||
|
* YAML Support
|
||||||
|
* This template specifically supports I18n based on YAML syntax, see `public/i18n/zh_CN.yaml`
|
||||||
|
* During compilation, the defined YAML files will be automatically translated into JSON files and placed in the dist or dev directory.
|
||||||
|
|
||||||
It is recommended that the plugin supports at least English and Simplified Chinese, so that more people can use it more
|
It is recommended that the plugin supports at least English and Simplified Chinese, so that more people can use it more
|
||||||
conveniently.
|
conveniently.
|
||||||
|
@ -246,43 +249,12 @@ Related APIs can be found at: `/api/file/*` (e.g., `/api/file/getFile`).
|
||||||
|
|
||||||
### 2. Daily Note Attribute Specifications
|
### 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.
|
When creating a daily note 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).
|
> 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:
|
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 `/api/filetree/createDailyNote` is called to create a daily note, 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.
|
* If a document is created manually by developer's code (e.g., using the `createDocWithMd` API to create a daily note), 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);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
@ -62,9 +62,12 @@
|
||||||
* 插件自身的元信息,比如插件描述和自述文件
|
* 插件自身的元信息,比如插件描述和自述文件
|
||||||
* plugin.json 中的 `description` 和 `readme` 字段,以及对应的 README*.md 文件
|
* plugin.json 中的 `description` 和 `readme` 字段,以及对应的 README*.md 文件
|
||||||
* 插件中使用的文本,比如按钮文字和提示信息
|
* 插件中使用的文本,比如按钮文字和提示信息
|
||||||
* src/i18n/*.json 语言配置文件
|
* public/i18n/*.json 语言配置文件
|
||||||
* 代码中使用 `this.i18.key` 获取文本
|
* 代码中使用 `this.i18.key` 获取文本
|
||||||
* 最后在 plugin.json 中的 `i18n` 字段中声明该插件支持的语言
|
* 最后在 plugin.json 中的 `i18n` 字段中声明该插件支持的语言
|
||||||
|
* yaml 支持
|
||||||
|
* 本模板特别支持基于 Yaml 语法的 I18n,见 `public/i18n/zh_CN.yaml`
|
||||||
|
* 编译时,会自动把定义的 yaml 文件翻译成 json 文件放到 dist 或 dev 目录下
|
||||||
|
|
||||||
建议插件至少支持英文和简体中文,这样可以方便更多人使用。
|
建议插件至少支持英文和简体中文,这样可以方便更多人使用。
|
||||||
|
|
||||||
|
@ -234,47 +237,15 @@ PR 社区集市仓库。
|
||||||
|
|
||||||
插件或者外部扩展如果有直接读取或者写入 data 下文件的需求,请通过调用内核 API 来实现,**不要自行调用 `fs` 或者其他 electron、nodejs API**,否则可能会导致数据同步时分块丢失,造成云端数据损坏。
|
插件或者外部扩展如果有直接读取或者写入 data 下文件的需求,请通过调用内核 API 来实现,**不要自行调用 `fs` 或者其他 electron、nodejs API**,否则可能会导致数据同步时分块丢失,造成云端数据损坏。
|
||||||
|
|
||||||
相关 API 见: `/api/file/*`(例如 `/api/file/getFile` 等)。
|
相关 API 见 `/api/file/*`(例如 `/api/file/getFile` 等)。
|
||||||
|
|
||||||
### 2. Daily Note 属性规范
|
### 2. Daily Note 属性规范
|
||||||
|
|
||||||
思源在创建日记的时候会自动为文档添加 custom-dailynote-yyyymmdd 属性, 以方便将日记文档同普通文档区分。
|
思源在创建日记的时候会自动为文档添加 custom-dailynote-yyyymmdd 属性,以方便将日记文档同普通文档区分。
|
||||||
|
|
||||||
> 详情请见 [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807)。
|
> 详情请见 [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807)。
|
||||||
|
|
||||||
开发者在开发手动创建 Daily Note 的功能时请注意:
|
开发者在开发手动创建 Daily Note 的功能时请注意:
|
||||||
|
|
||||||
- 如果调用了 `/api/filetree/createDailyNote` 创建日记,那么文档会自动添加这个属性,无需开发者特别处理。
|
* 如果调用了 `/api/filetree/createDailyNote` 创建日记,那么文档会自动添加这个属性,无需开发者特别处理
|
||||||
- 如果是开发者代码手动创建文档(例如使用 `createDocWithMd` API 创建日记),请手动为文档添加该属性。
|
* 如果是开发者代码手动创建文档(例如使用 `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);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
13
package.json
13
package.json
|
@ -11,24 +11,25 @@
|
||||||
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
|
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
|
||||||
"dev": "vite build --watch",
|
"dev": "vite build --watch",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"install": "vite build && node --no-warnings ./scripts/make_install.js"
|
"make-install": "vite build && node --no-warnings ./scripts/make_install.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^2.4.1",
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||||
"@tsconfig/svelte": "^4.0.1",
|
"@tsconfig/svelte": "^4.0.1",
|
||||||
"@types/node": "^20.3.0",
|
"@types/node": "^20.3.0",
|
||||||
"eslint": "^8.42.0",
|
"eslint": "^8.42.0",
|
||||||
"fast-glob": "^3.2.12",
|
"fast-glob": "^3.2.12",
|
||||||
"glob": "^7.2.3",
|
"glob": "^7.2.3",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"rollup-plugin-livereload": "^2.0.5",
|
"rollup-plugin-livereload": "^2.0.5",
|
||||||
"sass": "^1.63.3",
|
"sass": "^1.63.3",
|
||||||
"siyuan": "0.9.4",
|
"siyuan": "0.9.7",
|
||||||
"svelte": "^3.59.1",
|
"svelte": "^4.2.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.1.3",
|
"typescript": "^5.1.3",
|
||||||
"vite": "^4.5.2",
|
"vite": "^5.0.0",
|
||||||
"vite-plugin-static-copy": "^0.15.0",
|
"vite-plugin-static-copy": "^1.0.2",
|
||||||
"vite-plugin-zip-pack": "^1.0.5"
|
"vite-plugin-zip-pack": "^1.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"addTopBarIcon": "使用插件添加一个顶栏按钮",
|
|
||||||
"cancel": "取消",
|
|
||||||
"save": "保存",
|
|
||||||
"byeMenu": "再见,菜单!",
|
|
||||||
"helloPlugin": "你好,插件!",
|
|
||||||
"byePlugin": "再见,插件!",
|
|
||||||
"showDialog": "弹出一个对话框",
|
|
||||||
"removedData": "数据已删除",
|
|
||||||
"confirmRemove": "确认删除 ${name} 中的数据?",
|
|
||||||
"insertEmoji": "插入表情",
|
|
||||||
"removeSpace": "移除空格",
|
|
||||||
"getTab": "在日志中打印出已打开的所有自定义页签",
|
|
||||||
"name": "思源",
|
|
||||||
"hello": {
|
|
||||||
"makesure": "使用这个模板之前,请阅读<a href=\"https://github.com/siyuan-note/plugin-sample\">官方教程</a>, 确保自己已经理解了插件的基本开发流程。"
|
|
||||||
},
|
|
||||||
"hintTitle":"关于",
|
|
||||||
"hintDesc":"<a href='https://github.com/siyuan-note/plugin-sample-vite-svelte'>🔗 plugin-sample-vite-svelte</a><br>💻 @frostime<br>💻 @88250<br>💻 @zxkmm"
|
|
||||||
|
|
||||||
}
|
|
21
public/i18n/zh_CN.yaml
Normal file
21
public/i18n/zh_CN.yaml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
addTopBarIcon: 使用插件添加一个顶栏按钮
|
||||||
|
cancel: 取消
|
||||||
|
save: 保存
|
||||||
|
byeMenu: 再见,菜单!
|
||||||
|
helloPlugin: 你好,插件!
|
||||||
|
byePlugin: 再见,插件!
|
||||||
|
showDialog: 弹出一个对话框
|
||||||
|
removedData: 数据已删除
|
||||||
|
confirmRemove: 确认删除 ${name} 中的数据?
|
||||||
|
insertEmoji: 插入表情
|
||||||
|
removeSpace: 移除空格
|
||||||
|
getTab: 在日志中打印出已打开的所有自定义页签
|
||||||
|
name: 思源
|
||||||
|
hello:
|
||||||
|
makesure: 使用这个模板之前,请阅读<a href="https://github.com/siyuan-note/plugin-sample">官方教程</a>,
|
||||||
|
确保自己已经理解了插件的基本开发流程。
|
||||||
|
hintTitle: 关于
|
||||||
|
hintDesc: "<a href='https://github.com/siyuan-note/plugin-sample-vite-svelte'>\U0001F517
|
||||||
|
plugin-sample-vite-svelte</a><br>\U0001F4BB @frostime<br>\U0001F4BB @88250<br>\U0001F4BB
|
||||||
|
@zxkmm"
|
|
@ -63,6 +63,7 @@
|
||||||
<div class="fn__flex-1 fn__flex config__panel">
|
<div class="fn__flex-1 fn__flex config__panel">
|
||||||
<ul class="b3-tab-bar b3-list b3-list--background">
|
<ul class="b3-tab-bar b3-list b3-list--background">
|
||||||
{#each groups as group}
|
{#each groups as group}
|
||||||
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
<li
|
<li
|
||||||
data-name="editor"
|
data-name="editor"
|
||||||
class:b3-list-item--focus={group === focusGroup}
|
class:b3-list-item--focus={group === focusGroup}
|
||||||
|
|
|
@ -1,7 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 by frostime. All Rights Reserved.
|
||||||
|
* @Author : frostime
|
||||||
|
* @Date : 2023-05-19 19:49:13
|
||||||
|
* @FilePath : /svelte.config.js
|
||||||
|
* @LastEditTime : 2024-04-19 19:01:55
|
||||||
|
* @Description :
|
||||||
|
*/
|
||||||
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
|
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
|
||||||
|
|
||||||
|
const NoWarns = new Set([
|
||||||
|
"a11y-click-events-have-key-events",
|
||||||
|
"a11y-no-static-element-interactions",
|
||||||
|
"a11y-no-noninteractive-element-interactions"
|
||||||
|
]);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||||
// for more information about preprocessors
|
// for more information about preprocessors
|
||||||
preprocess: vitePreprocess(),
|
preprocess: vitePreprocess(),
|
||||||
|
onwarn: (warning, handler) => {
|
||||||
|
// suppress warnings on `vite dev` and `vite build`; but even without this, things still work
|
||||||
|
if (NoWarns.has(warning.code)) return;
|
||||||
|
handler(warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@ import { svelte } from "@sveltejs/vite-plugin-svelte"
|
||||||
import zipPack from "vite-plugin-zip-pack";
|
import zipPack from "vite-plugin-zip-pack";
|
||||||
import fg from 'fast-glob';
|
import fg from 'fast-glob';
|
||||||
|
|
||||||
|
import vitePluginYamlI18n from './yaml-plugin';
|
||||||
|
|
||||||
const args = minimist(process.argv.slice(2))
|
const args = minimist(process.argv.slice(2))
|
||||||
const isWatch = args.watch || args.w || false
|
const isWatch = args.watch || args.w || false
|
||||||
const devDistDir = "./dev"
|
const devDistDir = "dev"
|
||||||
const distDir = isWatch ? devDistDir : "./dist"
|
const distDir = isWatch ? devDistDir : "dist"
|
||||||
|
|
||||||
console.log("isWatch=>", isWatch)
|
console.log("isWatch=>", isWatch)
|
||||||
console.log("distDir=>", distDir)
|
console.log("distDir=>", distDir)
|
||||||
|
@ -25,6 +27,11 @@ export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
svelte(),
|
svelte(),
|
||||||
|
|
||||||
|
vitePluginYamlI18n({
|
||||||
|
inDir: 'public/i18n',
|
||||||
|
outDir: `${distDir}/i18n`
|
||||||
|
}),
|
||||||
|
|
||||||
viteStaticCopy({
|
viteStaticCopy({
|
||||||
targets: [
|
targets: [
|
||||||
{
|
{
|
||||||
|
|
60
yaml-plugin.js
Normal file
60
yaml-plugin.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 by frostime. All Rights Reserved.
|
||||||
|
* @Author : frostime
|
||||||
|
* @Date : 2024-04-05 21:27:55
|
||||||
|
* @FilePath : /yaml-plugin.js
|
||||||
|
* @LastEditTime : 2024-04-05 22:53:34
|
||||||
|
* @Description : 去妮玛的 json 格式,我就是要用 yaml 写 i18n
|
||||||
|
*/
|
||||||
|
// plugins/vite-plugin-parse-yaml.js
|
||||||
|
import fs from 'fs';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
|
export default function vitePluginYamlI18n(options = {}) {
|
||||||
|
// Default options with a fallback
|
||||||
|
const DefaultOptions = {
|
||||||
|
inDir: 'src/i18n',
|
||||||
|
outDir: 'dist/i18n',
|
||||||
|
};
|
||||||
|
|
||||||
|
const finalOptions = { ...DefaultOptions, ...options };
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: 'vite-plugin-yaml-i18n',
|
||||||
|
buildStart() {
|
||||||
|
console.log('🌈 Parse I18n: YAML to JSON..');
|
||||||
|
const inDir = finalOptions.inDir;
|
||||||
|
const outDir = finalOptions.outDir
|
||||||
|
|
||||||
|
if (!fs.existsSync(outDir)) {
|
||||||
|
fs.mkdirSync(outDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
//Parse yaml file, output to json
|
||||||
|
const files = fs.readdirSync(inDir);
|
||||||
|
for (const file of files) {
|
||||||
|
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
||||||
|
console.log(`-- Parsing ${file}`)
|
||||||
|
//检查是否有同名的json文件
|
||||||
|
const jsonFile = file.replace(/\.(yaml|yml)$/, '.json');
|
||||||
|
if (files.includes(jsonFile)) {
|
||||||
|
console.log(`---- File ${jsonFile} already exists, skipping...`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const filePath = resolve(inDir, file);
|
||||||
|
const fileContents = fs.readFileSync(filePath, 'utf8');
|
||||||
|
const parsed = yaml.load(fileContents);
|
||||||
|
const jsonContent = JSON.stringify(parsed, null, 2);
|
||||||
|
const outputFilePath = resolve(outDir, file.replace(/\.(yaml|yml)$/, '.json'));
|
||||||
|
console.log(`---- Writing to ${outputFilePath}`);
|
||||||
|
fs.writeFileSync(outputFilePath, jsonContent);
|
||||||
|
} catch (error) {
|
||||||
|
this.error(`---- Error parsing YAML file ${file}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue