summarize-links
{{#script}}
// Get current file safely
const file = app.workspace.getActiveFile();
if (!file) {
this.related_notes = “No active file.“;
return “”;
}
const cache = app.metadataCache.getFileCache(file) || {};
let tags = cache?.frontmatter?.tags || [];
// Normalize tag list into an array
let tagList = [];
if (typeof tags === “string”) {
tagList = tags.split(“,”).map(t => t.trim());
} else if (Array.isArray(tags)) {
tagList = tags;
}
const related = [];
const files = app.vault.getMarkdownFiles();
for (const f of files) {
if (f.path === file.path) continue;
const fCache = app.metadataCache.getFileCache(f) || {};
let fTags = fCache?.frontmatter?.tags || [];
let fTagList = [];
if (typeof fTags === “string”) {
fTagList = fTags.split(“,”).map(t => t.trim());
} else if (Array.isArray(fTags)) {
fTagList = fTags;
}
// Only proceed if at least one tag overlaps
if (tagList.length && tagList.some(t => fTagList.includes(t))) {
try {
const text = await app.vault.cachedRead(f);
const excerpt = text.split(“\n”).slice(0, 3).join(” “);
related.push(- [[${f.basename}]]: ${excerpt});
} catch (err) {
console.error(Error reading ${f.basename}:, err);
}
}
}
this.related_notes = related.length > 0
? related.join(“\n”)
: “No related notes found.“;
return “”; // only sets context
{{/script}}
Summarize the following note clearly and concisely.
When relevant, insert Obsidian wiki-links like Note Title to related notes provided.
Do not force links if they don’t fit naturally.
Current note
{{content}}
Related notes (titles + excerpts)
{{related_notes}}
Unlinked Mention to link
(only one link per page use the most appropriate one)
{{#each mentions.unlinked}}
-
{{this.results}}
{{/each}}
{{output}}