fix: more robust tags parsing

This commit is contained in:
Jacky Zhao 2023-12-28 08:48:14 -08:00
parent dafc9f318e
commit 359484c139

View file

@ -49,13 +49,21 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options> | undefined>
data.title = file.stem ?? "Untitled" data.title = file.stem ?? "Untitled"
} }
if (data.tags && !Array.isArray(data.tags)) { if (data.tags) {
// coerce to array
if (!Array.isArray(data.tags)) {
data.tags = data.tags data.tags = data.tags
.toString() .toString()
.split(oneLineTagDelim) .split(oneLineTagDelim)
.map((tag: string) => tag.trim()) .map((tag: string) => tag.trim())
} }
// remove all non-string tags
data.tags = data.tags
.filter((tag: unknown) => typeof tag === "string" || typeof tag === "number")
.map((tag: string | number) => tag.toString())
}
// slug them all!! // slug them all!!
data.tags = [...new Set(data.tags?.map((tag: string) => slugTag(tag)))] data.tags = [...new Set(data.tags?.map((tag: string) => slugTag(tag)))]