backlinks.mjs
39 lines 1.2 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… 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 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 10 days ago