Fixed #48 - Highly favor tags in search results

This commit is contained in:
Simon Cambier
2022-06-17 19:56:10 +02:00
parent 21f936e4ee
commit 6e604988f4
4 changed files with 38 additions and 2 deletions

View File

@@ -144,6 +144,20 @@ export function getAliasesFromMetadata(
.filter(s => !!s)
}
export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] {
const arrOrString = metadata?.frontmatter?.tags ?? []
const fromFrontMatter = (
Array.isArray(arrOrString) ? arrOrString : arrOrString.split(',')
)
.map(s => (s ? s.trim() : s))
.filter(s => !!s)
const fromBody = (metadata?.tags ?? []).map(t => t.tag)
return [...fromFrontMatter, ...fromBody].map(t =>
t[0] !== '#' ? '#' + t : t,
)
}
/**
* https://stackoverflow.com/a/37511463
*/