fix: keep neighborhood reverse matches path-aware

This commit is contained in:
lucaronin
2026-04-19 12:53:07 +02:00
parent 9534449307
commit 80c13272f3
2 changed files with 46 additions and 1 deletions

View File

@@ -163,4 +163,37 @@ describe('buildRelationshipGroups', () => {
expect(groups.find((group) => group.label === 'Related to')?.entries).toEqual([shared])
expect(groups.find((group) => group.label === 'Referenced By')?.entries).toEqual([shared])
})
it('does not treat path-qualified refs for a different note as reverse matches', () => {
const parent = makeEntry({
path: '/vault/projects/alpha.md',
filename: 'alpha.md',
title: 'Alpha',
isA: 'Project',
})
const archiveAlpha = makeEntry({
path: '/vault/archive/alpha.md',
filename: 'alpha.md',
title: 'Alpha Archive',
isA: 'Project',
})
const unrelatedChild = makeEntry({
path: '/vault/notes/child.md',
filename: 'child.md',
title: 'Child Note',
isA: 'Note',
belongsTo: ['[[archive/alpha]]'],
})
const unrelatedEvent = makeEntry({
path: '/vault/events/event.md',
filename: 'event.md',
title: 'Review',
isA: 'Event',
relatedTo: ['[[archive/alpha]]'],
})
const groups = buildRelationshipGroups(parent, [parent, archiveAlpha, unrelatedChild, unrelatedEvent])
expect(groups).toEqual([])
})
})

View File

@@ -67,8 +67,20 @@ export function formatSearchSubtitle(entry: VaultEntry): string {
return parts.join(' \u00b7 ')
}
function refMatchesEntry(ref: string, entry: VaultEntry): boolean {
const target = wikilinkTarget(ref).trim()
if (!target) return false
if (target.includes('/')) {
const normalizedTarget = target.replace(/^\/+/, '').replace(/\.md$/, '').toLowerCase()
return entry.path.toLowerCase().endsWith(`/${normalizedTarget}.md`)
}
return resolveEntry([entry], target) !== undefined
}
function refsMatch(refs: string[], entry: VaultEntry): boolean {
return refs.some((ref) => resolveEntry([entry], wikilinkTarget(ref)) !== undefined)
return refs.some((ref) => refMatchesEntry(ref, entry))
}
function resolveRefs(refs: string[], entries: VaultEntry[]): VaultEntry[] {