插件开发 0 篇文章

刷新文档

seehttps://github.com/siyuan-note/siyuan/issues/10243protyle.reloadthis.protyleSlash=[{filter:["insertemoji\u{1F60A}","\u63D2\u5165\u8868\u60C5\u{1F60A}","crbqwx"],html:`<divclass="b3-list-item__first"

提供重建单个文档索引的 API

seehttps://github.com/siyuan-note/siyuan/issues/5719 这个接口暂时不加入 API 文档中;使用方式如下:POSThttp://127.0.0.1:6806/api/filetree/reindexTree{"path":"/data/20210808180117-czj9bvb/20200812220555-lj3enxa.sy"}

生成文档树列表项

seehttps://ld246.com/article/1741359650489pc 端//第一步调用 listDocsByPath 获取文档树文档信息//fetchSyncPost('/api/filetree/listDocsByPath',{notebook:'20240723175050-336994k',path:'/20240728220858-adaleye'})//第二步调用 genFi

思源事件原理

思源事件原理
思源把插件名称生成注释 dom 结点,然后把相关事件绑定其上,在需要触发的地方通过遍历所有插件,调用 emit 进行触发。seehttps://github.com/siyuan-note/siyuan/blob/0b0c27b0bad3e2a073f61ed28c6ce76d2f2b4b07/app/src/plugin/EventBus.ts#L7 示例:seehttps://ld246.com/arti

行内自定义元素和属性

行内自定义元素和属性
seehttps://github.com/siyuan-note/siyuan/issues/13325 关联:块自定义元素和属性只能用 span,且不能嵌套,只能叠加自定义属性 custom-xxx 和 data-type 值修改或生成后,需要调用 input 事件触发比如:letmemoELement=document.querySelector(`span[data-id="${newBlockId}"]`

创建指定日期的日记

seehttps://ld246.com/article/1741777522652 参考这个:https://github.com/frostime/siyuan-plugin-kits/blob/667c2621ebc6fa11028e4e53e447afc5f00639ea/src/dailynote.ts#L72 不想自己实现也可以手动安装 npminstall@frostime/siyuan-p

调用 Lute 的正确方式

seehttps://github.com/siyuan-note/siyuan/issues/14310seehttps://ld246.com/article/1741527865453‍调用方式:getLute().Md2BlockDOM(xxxxx);​封装函数如下:functiongetLute(){constsetLute=(options)=>{constlute=window.Lut

判断是否空文档的方法

/api/block/getTreeStat 传入文档 id 即可,返回值有个字段 runeCount​代表字符个数的意思 0 是空文档,大于 0 非空文档缺点:由于 api 一次性读入 sy 文件到内存,文件大的话有性能瓶颈通过/api/filetree/getDoc 获取文档的内容,由于这个 api 是动态加载,一般不会加载太多内容,然后空文档的时候,这个返回结果的 content 字段长度是 239,可以依据这长度判断,比如大于

发送消息 showMessage 自定义窗口内容

//发送通知 showMessage(` 模板导出成功 <br/> 路径:${templatesPath.replace(/\/+$/,'')}`);if(isPc()){constmsgContent=awaitwhenElementExist("#message.b3-snackbar__content");constbr=document.createElement("br");constbutton

动态加载代码片段

seehttps://ld246.com/article/1736035967300/comment/1736126600837?r=wilsons#comments 如果是代码片段,可以动态加载 js,然后,用 vscode 编辑 js 文件就可以了比如代码片段输入{//动态加载 jsconstsrc='/snippets/query.js';constscript=document.createElement

修改新窗口大小

seehttps://github.com/siyuan-note/siyuan/blob/914c7659388e645395e70224f0d831950275eb05/app/src/window/openNewWindow.ts#L21seehttps://gitee.com/wish163/mysoft/blob/main/%E6%80%9D%E6%BA%90/%E6%80%9D%E6%B

监听全屏和退出全屏

seehttps://ld246.com/article/1731698559408 通过监听 window.siyuan.editorIsFullscreen 对象的变化实现//定义一个可观察的属性 window.siyuan._editorIsFullscreen=window.siyuan.editorIsFullscreen||false;Object.defineProperty(window.s

如何读取 S3 加密数据

https://github.com/siyuan-note/oceanpress/tree/main/apps/frontend/src/websiteseehttps://ld246.com/article/1734924497915oceanpress-apps-frontend-src.zip‍

检查代码片段是否有更新方案

如果需要执行多个网络请求来判断插件列表是否有更新,选择合适的方案取决于以下几个因素:任务的性质:网络请求是 I/O 密集型任务,通常不会占用大量 CPU 资源。任务的依赖关系:是否需要等待所有请求完成后再处理结果。性能和资源需求:是否需要并发执行多个请求以提高效率。以下是几种适合处理网络请求的方案:1.​Promise.all​​适用场景:需要并发执行多个网络请求,且任务之间没有依赖关系。优点:并发执行多个

模板大全

进度条模板.action{$a:=index."进度"}.action{$d:=float64$a}<spanstyle="background-color:rgba(175,184,193,0.2);width:100%;display:inline-block;height:12px;border-radius:6px;align-self:center;overflow:hidden;"><!

编辑器 toolbar 被添加事件

toolbar 被添加事件(async()=>{observeToolbar((el)=>{console.log(el,'toolbar');});//监听 toolbar 被添加 functionobserveToolbar(callback){//创建一个观察者实例并传入回调函数 constobserver=newMutationObserver((mutationsList,observer)=>{f

css 大全

css 选择 xlink:href 属性 seehttps://ld246.com/article/1734427196426@namespacexlink'http://www.w3.org/1999/xlink';.protyle-breadcrumb__item:has(use[xlink|href*=iconListItem]).protyle-breadcrumb__text{display:no

启动时最小化到托盘

seehttps://ld246.com/article/1734430072051//启动时最小化到托盘//seehttps://github.com/siyuan-note/siyuan/blob/5129ad926a21176a352cf5f630e0651011bf9c83/app/src/boot/onGetConfig.ts#L115if(!localStorage.getItem('_