0-1开发自己的obsidian plugin DAY 6

今天也没少写bug,遇到了离奇的问题,很难说已经了解具体原因。阶段性总结分享一下目前比较确定的内容。

我想要实现的功能是从settingtab获取键入的内容并且另外保存到一个.json文件中。

一种可行的方式是先用:

复制代码
const absPath = app.vault.adapter.basePath;
const PATH_TO_JSON = `${absPath}/.obsidian/plugins/your-plugin-name/src/data.json`;

提供当前打开的 Obsidian 笔记库的绝对路径(注意替换这里的your-plugin-name和最后的data.json)

再用fs写入你的data_to_save:

复制代码
import * as fs from 'fs';

const jsonString = JSON.stringify(data_to_save, null, 2);
//new Notice(`Saving settings to ${PATH_TO_JSON}`);
await fs.promises.writeFile(PATH_TO_JSON, jsonString, 'utf8');

中间copilot/chatgpt给我提供了两种比较迷的解法,

一是`${this.manifest.dir},它只能获取从.obsidian之后的(半截子)路径,所以总是写不成功(害我一直去检查拼写 明明都是对的)

二是__dirname,这个的路径是:Applications/obsidian.app/contents/resources/electron.asar/renderer

这两个都是不可以的。

相关推荐
晚安日记wanna3 小时前
TS const 类型参数一道面试题的四层追问
前端·面试·typescript
掰头战士3 小时前
你说你折这玩意干什么-agent工作的核心,还真得好好考虑怎么折叠上下文
typescript·llm·agent
ynchyong3 小时前
VUE 中 不能将类型“R[]”分配给类型“UnwrapRefSimple<R>[]”
typescript·vue·ts·unwraprefsimple
掰头战士5 小时前
让散乱的工具调用成为正规军,今天咱们聊聊 Tool System管线的读写锁
typescript·llm·agent
半糖程序员9 小时前
从零构建 Agent(5):让事件流同时提供过程和结果
typescript·agent
西瓜太郎123419 小时前
外层模型卡片与分组详情成功率不一致,应该怎么排查?
前端·typescript·go·软件工程·react
掰头战士1 天前
MCP、Skill、Plugin,都是给agent拓展能力,到底有何区别?
typescript·llm·agent
掰头战士1 天前
聊聊 Function Calling,你的模型是否答非所问?
前端·typescript·agent