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

这两个都是不可以的。

相关推荐
红尘散仙10 小时前
TypeScript WIT Guest:类型约束与 ComponentizeJS 工程化
rust·typescript·webassembly
红尘散仙11 小时前
从 dsh 的插件系统出发:为什么我要探索 WIT 与 Wasm Component Model
rust·typescript·webassembly
红尘散仙11 小时前
从 WIT 到 Wasmtime:构建 Rust Component 工程
rust·typescript·webassembly
记忆张量MemTensor13 小时前
产品更新|MemOS 现已支持 DeepSeek Harness 长期记忆接入
人工智能·typescript·开源·agent
记忆张量MemTensor18 小时前
MemOS Skill 上线|一句话即可接入 MemOS Cloud
大数据·数据库·人工智能·typescript·开源
YIAN1 天前
端侧大模型:DeepSeek-R1 WebGPU 推理全流程源码深度解析
前端·typescript·deepseek
苏灿烤鱼1 天前
把求职写成工作流,公开 fork 为什么会把简历写进仓库?
python·typescript·claude
古夕2 天前
Vue 3 严格模式下,可选接口字段为什么会炸:一次上架页 TypeScript 复盘
typescript
EricStone2 天前
Agent开发学习一:Hello-Agents TypeScript 全栈实现
typescript·node.js·agent
YIAN2 天前
TS 面试必考题:type 与 interface 的 6 大核心区别,90% 的人答不全
前端·typescript