Skip to content

Commit

Permalink
📝 完整文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Achuan-2 committed Oct 10, 2024
1 parent e306ff3 commit 3b58e4e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 342 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Changelog

## v0.0.1 / 2024.10.10 🎉 第一次提交
- 支持格式刷功能
- 已知bug:不支持数学公式格式刷

179 changes: 7 additions & 172 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,176 +1,11 @@
[中文](.README_zh_CN.md)

# SiYuan plugin sample
## Feature Introduction

## Get started
- Enter Format Painter Mode: Select text, click the "Format Painter" button on the floating toolbar to copy styles (supports layered styles), then select other text to automatically and quickly apply the copied styles.
- Supported inline styles: no style, background color, text color, bold, inline code, keyboard style, underline, strikethrough, superscript, subscript, highlight, etc.
- Exit Format Painter Mode: Press the Esc key.

* Make a copy of this repo as a template with the <kbd>Use this template</kbd> button, please note that the repo name
must be the same as the plugin name, the default branch must be `main`
* Clone your repo to a local development folder. For convenience, you can place this folder in
your `{workspace}/data/plugins/` folder
* Install [NodeJS](https://nodejs.org/en/download) and [pnpm](https://pnpm.io/installation), then run `pnpm i` in the
command line under your repo folder
* Execute `pnpm run dev` for real-time compilation
* Open SiYuan marketplace and enable plugin in downloaded tab

## Development

* i18n/*
* icon.png (160*160)
* index.css
* index.js
* plugin.json
* preview.png (1024*768)
* README*.md
* [Fontend API](https://github.com/siyuan-note/petal)
* [Backend API](https://github.com/siyuan-note/siyuan/blob/master/API.md)

## I18n

In terms of internationalization, our main consideration is to support multiple languages. Specifically, we need to
complete the following tasks:

* 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
* Text used in the plugin, such as button text and tooltips
* src/i18n/*.json language configuration files
* Use `this.i18.key` to get the text in the code
* Finally, declare the language supported by the plugin in the `i18n` field in plugin.json

It is recommended that the plugin supports at least English and Simplified Chinese, so that more people can use it more
conveniently.

## plugin.json

```json
{
"name": "plugin-sample",
"author": "Vanessa",
"url": "https://github.com/siyuan-note/plugin-sample",
"version": "0.1.3",
"minAppVersion": "2.8.8",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop"],
"displayName": {
"default": "Plugin Sample",
"zh_CN": "插件示例"
},
"description": {
"default": "This is a plugin sample",
"zh_CN": "这是一个插件示例"
},
"readme": {
"default": "README.md",
"zh_CN": "README_zh_CN.md"
},
"funding": {
"openCollective": "",
"patreon": "",
"github": "",
"custom": [
"https://ld246.com/sponsor"
]
},
"keywords": [
"sample", "示例"
]
}
```

* `name`: Plugin name, must be the same as the repo name, and must be unique globally (no duplicate plugin names in the
marketplace)
* `author`: Plugin author name
* `url`: Plugin repo URL
* `version`: Plugin version number, it is recommended to follow the [semver](https://semver.org/) specification
* `minAppVersion`: Minimum version number of SiYuan required to use this plugin
* `backends`: Backend environment required by the plugin, optional values are `windows`, `linux`, `darwin`, `docker`, `android`, `ios` and `all`
* `windows`: Windows desktop
* `linux`: Linux desktop
* `darwin`: macOS desktop
* `docker`: Docker
* `android`: Android APP
* `ios`: iOS APP
* `all`: All environments
* `frontends`: Frontend environment required by the plugin, optional values are `desktop`, `desktop-window`, `mobile`, `browser-desktop`, `browser-mobile` and `all`
* `desktop`: Desktop
* `desktop-window`: Desktop window converted from tab
* `mobile`: Mobile APP
* `browser-desktop`: Desktop browser
* `browser-mobile`: Mobile browser
* `all`: All environments
* `displayName`: Template display name, mainly used for display in the marketplace list, supports multiple languages
* `default`: Default language, must exist
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
* `description`: Plugin description, mainly used for display in the marketplace list, supports multiple languages
* `default`: Default language, must exist
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
* `readme`: readme file name, mainly used to display in the marketplace details page, supports multiple languages
* `default`: Default language, must exist
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
* `funding`: Plugin sponsorship information
* `openCollective`: Open Collective name
* `patreon`: Patreon name
* `github`: GitHub login name
* `custom`: Custom sponsorship link list
* `keywords`: Search keyword list, used for marketplace search function

## Package

No matter which method is used to compile and package, we finally need to generate a package.zip, which contains at
least the following files:

* i18n/*
* icon.png (160*160)
* index.css
* index.js
* plugin.json
* preview.png (1024*768)
* README*.md

## List on the marketplace

* `pnpm run build` to generate package.zip
* Create a new GitHub release using your new version number as the "Tag version". See here for an
example: https://github.com/siyuan-note/plugin-sample/releases
* Upload the file package.zip as binary attachments
* Publish the release

If it is the first release, please create a pull request to
the [Community Bazaar](https://github.com/siyuan-note/bazaar) repository and modify the plugins.json file in it. This
file is the index of all community plugin repositories, the format is:

```json
{
"repos": [
"username/reponame"
]
}
```

After the PR is merged, the bazaar will automatically update the index and deploy through GitHub Actions. When releasing
a new version of the plugin in the future, you only need to follow the above steps to create a new release, and you
don't need to PR the community bazaar repo.

Under normal circumstances, the community bazaar repo will automatically update the index and deploy every hour,
and you can check the deployment status at https://github.com/siyuan-note/bazaar/actions.

## Developer's Guide

Developers 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 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).
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 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 daily note), please manually add this attribute to the document
## Known Bugs
- Currently does not support format painting for mathematical formulas.
- Styles copied by the format painter have no color; if the text to be painted already has color, it will not be replaced.
167 changes: 8 additions & 159 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,165 +1,14 @@
[English](./README.md)

# 思源笔记插件示例
## 功能介绍

## 开始
- 进入格式刷模式:选中文字,在悬浮工具栏点击「格式刷」按钮即可复制样式(支持叠加的样式),之后选中其他文字后自动快速添加复制的样式
- 支持的行内样式:无样式、背景色、文字颜色、加粗、行内代码、键盘样式、下划线、删除线、上标、下标、高亮等
- 退出格式刷模式:按Esc建即可

* 通过 <kbd>Use this template</kbd> 按钮将该库文件复制到你自己的库中,请注意库名必须和插件名称一致,默认分支必须为 `main`
* 将你的库克隆到本地开发文件夹中,为了方便可以直接将开发文件夹放置在 `{工作空间}/data/plugins/`
* 安装 [NodeJS](https://nodejs.org/en/download)[pnpm](https://pnpm.io/installation),然后在开发文件夹下执行 `pnpm i`
* 执行 `pnpm run dev` 进行实时编译
* 在思源中打开集市并在下载选项卡中启用插件
![](https://fastly.jsdelivr.net/gh/Achuan-2/PicBed/assets/思源笔记格式刷插件-2024-10-10.gif)

## 开发
## 已知bug
- 暂不支持数学公式格式刷
- 格式刷复制的样式无颜色,要刷的文字已有颜色,不会替换其颜色

* i18n/*
* icon.png (160*160)
* index.css
* index.js
* plugin.json
* preview.png (1024*768)
* README*.md
* [前端 API](https://github.com/siyuan-note/petal)
* [后端 API](https://github.com/siyuan-note/siyuan/blob/master/API_zh_CN.md)

## 国际化

国际化方面我们主要考虑的是支持多语言,具体需要完成以下工作:

* 插件自身的元信息,比如插件描述和自述文件
* plugin.json 中的 `description``readme` 字段,以及对应的 README*.md 文件
* 插件中使用的文本,比如按钮文字和提示信息
* src/i18n/*.json 语言配置文件
* 代码中使用 `this.i18.key` 获取文本
* 最后在 plugin.json 中的 `i18n` 字段中声明该插件支持的语言

建议插件至少支持英文和简体中文,这样可以方便更多人使用。

## plugin.json

```json
{
"name": "plugin-sample",
"author": "Vanessa",
"url": "https://github.com/siyuan-note/plugin-sample",
"version": "0.1.3",
"minAppVersion": "2.8.8",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop"],
"displayName": {
"default": "Plugin Sample",
"zh_CN": "插件示例"
},
"description": {
"default": "This is a plugin sample",
"zh_CN": "这是一个插件示例"
},
"readme": {
"default": "README.md",
"zh_CN": "README_zh_CN.md"
},
"funding": {
"openCollective": "",
"patreon": "",
"github": "",
"custom": [
"https://ld246.com/sponsor"
]
},
"keywords": [
"sample", "示例"
]
}
```

* `name`:插件名称,必须和库名一致,且全局唯一(集市中不能有重名插件)
* `author`:插件作者名
* `url`:插件仓库地址
* `version`:插件版本号,建议遵循 [semver](https://semver.org/lang/zh-CN/) 规范
* `minAppVersion`:插件支持的最低思源笔记版本号
* `backends`:插件需要的后端环境,可选值为 `windows`, `linux`, `darwin`, `docker`, `android`, `ios` and `all`
* `windows`:Windows 桌面端
* `linux`:Linux 桌面端
* `darwin`:macOS 桌面端
* `docker`:Docker 端
* `android`:Android 端
* `ios`:iOS 端
* `all`:所有环境
* `frontends`:插件需要的前端环境,可选值为 `desktop`, `desktop-window`, `mobile`, `browser-desktop`, `browser-mobile` and `all`
* `desktop`:桌面端
* `desktop-window`:桌面端页签转换的独立窗口
* `mobile`:移动端
* `browser-desktop`:桌面端浏览器
* `browser-mobile`:移动端浏览器
* `all`:所有环境
* `displayName`:模板显示名称,主要用于模板集市列表中显示,支持多语言
* `default`:默认语言,必须存在
* `zh_CN``en_US` 等其他语言:可选,建议至少提供中文和英文
* `description`:插件描述,主要用于插件集市列表中显示,支持多语言
* `default`:默认语言,必须存在
* `zh_CN``en_US` 等其他语言:可选,建议至少提供中文和英文
* `readme`:自述文件名,主要用于插件集市详情页中显示,支持多语言
* `default`:默认语言,必须存在
* `zh_CN``en_US` 等其他语言:可选,建议至少提供中文和英文
* `funding`:插件赞助信息
* `openCollective`:Open Collective 名称
* `patreon`:Patreon 名称
* `github`:GitHub 登录名
* `custom`:自定义赞助链接列表
* `keywords`:搜索关键字列表,用于集市搜索功能

## 打包

无论使用何种方式编译打包,我们最终需要生成一个 package.zip,它至少包含如下文件:

* i18n/*
* icon.png (160*160)
* index.css
* index.js
* plugin.json
* preview.png (1024*768)
* README*.md

## 上架集市

* 执行 `pnpm run build` 生成 package.zip
* 在 GitHub 上创建一个新的发布,使用插件版本号作为 “Tag version”,示例 https://github.com/siyuan-note/plugin-sample/releases
* 上传 package.zip 作为二进制附件
* 提交发布

如果是第一次发布版本,还需要创建一个 PR 到 [Community Bazaar](https://github.com/siyuan-note/bazaar) 社区集市仓库,修改该库的
plugins.json。该文件是所有社区插件库的索引,格式为:

```json
{
"repos": [
"username/reponame"
]
}
```

PR 被合并以后集市会通过 GitHub Actions 自动更新索引并部署。后续发布新版本插件时只需要按照上述步骤创建新的发布即可,不需要再
PR 社区集市仓库。

正常情况下,社区集市仓库每隔 1 小时会自动更新索引并部署,可在 https://github.com/siyuan-note/bazaar/actions 查看部署状态。

## 开发者须知

开发者需注意以下规范。

### 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 创建日记),请手动为文档添加该属性
Binary file modified icon.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 modified preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3b58e4e

Please sign in to comment.