MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / matchNote

Function matchNote

packages/app-core/src/lib/internal-links.ts:61–75  ·  view source on GitHub ↗
(notes: NoteRef[], target: string)

Source from the content-addressed store, hash-verified

59}
60
61function matchNote(notes: NoteRef[], target: string): string | null {
62 const visible = notes.filter((n) => n.folder !== 'trash')
63 // Markdown links usually carry the `.md`; tolerate links that omit it.
64 const candidates = /\.md$/i.test(target) ? [target] : [`${target}.md`, target]
65 for (const cand of candidates) {
66 const exact = visible.find((n) => lc(n.path) === lc(cand))
67 if (exact) return exact.path
68 }
69 // Basename fallback for a single unambiguous match — tolerates a link
70 // written before the note moved, mirroring wikilink path-suffix resolution.
71 const wantBase = lc(candidates[0].split('/').pop() ?? '')
72 if (!wantBase) return null
73 const baseMatches = visible.filter((n) => lc(n.path.split('/').pop() ?? '') === wantBase)
74 return baseMatches.length === 1 ? baseMatches[0].path : null
75}
76
77/**
78 * Resolve a Markdown link href to an internal note, relative to `notePath`.

Callers 1

resolveInternalNoteHrefFunction · 0.85

Calls 1

lcFunction · 0.85

Tested by

no test coverage detected