release: 1.8.2

This commit is contained in:
yan 2026-05-17 01:07:32 +08:00
parent cf4c5a3e65
commit 6fba79cf99
4 changed files with 32 additions and 11 deletions

View file

@ -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",

View file

@ -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": {

View file

@ -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(`(?<!\\[\\[)${this.escapeRegex(name)}(?!\\]\\])`, "g"),
`[[${name}]]`
);
if (linked !== sourceContent) {
await this.app.vault.modify(sourceFile, linked);
}
}
}
// 同时创建内容中引用的其他概念页
void this.ensureLinkedConcepts(content);
}
/** 扫描内容中的 [[双链]],为不存在的概念自动创建页面 */
private escapeRegex(str: string): string {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
/** 扫描内容中の [[双链]],为不存在的概念自动创建页面 */
private async ensureLinkedConcepts(content: string) {
const links = content.match(/\[\[([^\]|]+?)(?:\|[^\]]+?)?\]\]/g);
if (!links) return;

View file

@ -20,5 +20,6 @@
"1.7.7": "1.4.0",
"1.7.8": "1.7.2",
"1.8.0": "1.7.2",
"1.8.1": "1.7.2"
"1.8.1": "1.7.2",
"1.8.2": "1.7.2"
}