From 6fba79cf99d9f33bfeae67c13f84668d5bedfb20 Mon Sep 17 00:00:00 2001 From: yan Date: Sun, 17 May 2026 01:07:32 +0800 Subject: [PATCH] release: 1.8.2 --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 36 ++++++++++++++++++++++++++++-------- versions.json | 3 ++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index 3070f6f..09e4acd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "istart-note-ai", "name": "IStart-Note-AI", - "version": "1.8.1", + "version": "1.8.2", "minAppVersion": "1.7.2", "description": "Generate structured knowledge notes from questions and selected text using DeepSeek AI, with automatic concept pages, bidirectional links, and a question graph.", "author": "Yan", diff --git a/package.json b/package.json index 98eae44..f817ccd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "istart-note-ai", - "version": "1.8.1", + "version": "1.8.2", "description": "IStart-Note-AI: DeepSeek-powered knowledge graph plugin for Obsidian", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index ee9c64a..d8e1620 100644 --- a/src/main.ts +++ b/src/main.ts @@ -151,41 +151,61 @@ export default class DeepSeekPlugin extends Plugin { const conceptsPath = normalizePath(this.settings.conceptsPath || "Knowledge/Concepts"); const uncategorizedPath = normalizePath(`${conceptsPath}/_未分类`); + // 记录发起页面信息(在打开新文件之前) + const sourceFile = this.app.workspace.getActiveFile(); + const sourcePath = sourceFile?.path ?? ""; + const sourceEditor = this.app.workspace.activeEditor?.editor ?? null; + if (!this.app.vault.getAbstractFileByPath(uncategorizedPath)) { try { await this.app.vault.createFolder(uncategorizedPath); } catch { /* exists */ } } const filePath = normalizePath(`${uncategorizedPath}/${name}.md`); + const sourceLink = sourcePath ? `\n\n## 来源\n\n- 来自 [[${sourcePath}]]\n` : ""; // 如果已存在,追加内容 const existing = this.app.vault.getAbstractFileByPath(filePath); if (existing instanceof TFile) { const oldContent = await this.app.vault.read(existing); - await this.app.vault.modify(existing, oldContent.trimEnd() + "\n\n" + content + "\n"); + await this.app.vault.modify(existing, oldContent.trimEnd() + "\n\n" + content + sourceLink); new Notice(`✅ 已追加到概念页:${name}`); const leaf = this.app.workspace.getLeaf(false); await leaf.openFile(existing); } else { - // 创建新概念页 + // 创建新概念页(包含来源链接) const today = new Date().toISOString().slice(0, 10); - const fullContent = `---\ntype: concept\nname: ${name}\nstatus: completed\ncompletion_status: completed\ncreated_from: ai-assistant\ncreated_at: ${today}\n---\n\n# ${name}\n\n${content}\n`; + const fullContent = `---\ntype: concept\nname: ${name}\nstatus: completed\ncompletion_status: completed\ncreated_from: ai-assistant\nsource: "[[${sourcePath}]]"\ncreated_at: ${today}\n---\n\n# ${name}\n\n${content}${sourceLink}`; const file = await this.app.vault.create(filePath, fullContent); new Notice(`✅ 已创建概念页:${name}`); const leaf = this.app.workspace.getLeaf(false); await leaf.openFile(file); } - // 在原文档光标位置插入双链引用 - const editor = this.app.workspace.activeEditor?.editor; - if (editor) { - // 不在新打开的文件里插入,这里只是提示用户 + // 在原文档中将选中的概念词替换为 [[双链]] + if (sourceFile && sourceEditor && name) { + const selection = sourceEditor.getSelection(); + if (selection && !selection.includes("[[")) { + // 需要回到原文件修改 + const sourceContent = await this.app.vault.read(sourceFile); + const linked = sourceContent.replace( + new RegExp(`(?