backlinks.mjs
39 lines 1.2 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Reverse wikilink index (Issue #1 Phase C2).
3 */
4
5 import { listMarkdownFiles, readNote } from './vault.mjs';
6 import { findFirstWikilinkToTargetInBody, vaultBasenameTargetKey } from './wikilink.mjs';
7
8 /**
9 * @param {import('./config.mjs').loadConfig extends () => infer R ? R : never} config
10 * @param {string} vaultRelativePath - target note path
11 * @returns {{ path: string, backlinks: { path: string, title: string|null, context: string }[] }}
12 */
13 export function runBacklinks(config, vaultRelativePath) {
14 const target = vaultRelativePath.replace(/\\/g, '/');
15 const targetKey = vaultBasenameTargetKey(target);
16 const paths = listMarkdownFiles(config.vault_path, { ignore: config.ignore });
17 const backlinks = [];
18
19 for (const p of paths) {
20 const rel = p.replace(/\\/g, '/');
21 if (rel === target) continue;
22 let note;
23 try {
24 note = readNote(config.vault_path, p);
25 } catch (_) {
26 continue;
27 }
28 const body = note.body || '';
29 const context = findFirstWikilinkToTargetInBody(body, targetKey);
30 if (context == null) continue;
31 backlinks.push({
32 path: rel,
33 title: note.frontmatter?.title ?? null,
34 context,
35 });
36 }
37
38 return { path: target, backlinks };
39 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 50 days ago