#146 - Consider subtags as normal tags for search

This commit is contained in:
Simon Cambier
2023-01-06 15:29:59 +01:00
parent 7881120abd
commit b06153f5d9

View File

@@ -195,7 +195,25 @@ export function getAliasesFromMetadata(
} }
export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] { export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] {
return metadata ? getAllTags(metadata) ?? [] : [] let tags = metadata ? getAllTags(metadata) ?? [] : []
// This will "un-nest" tags that are in the form of "#tag/subtag"
// A tag like "#tag/subtag" will be split into 3 tags: '#tag/subtag", "#tag" and "#subtag"
// https://github.com/scambier/obsidian-omnisearch/issues/146
tags = [
...new Set(
tags.reduce((acc, tag) => {
return [
...acc,
...tag
.split('/')
.filter(t => t)
.map(t => (t.startsWith('#') ? t : `#${t}`)),
tag,
]
}, [] as string[])
),
]
return tags
} }
/** /**