(notes: NoteRef[], target: string)
| 59 | } |
| 60 | |
| 61 | function 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`. |
no test coverage detected