From 359484c139c074e60f188616b3f6435cde46c42e Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Thu, 28 Dec 2023 08:48:14 -0800 Subject: [PATCH] fix: more robust tags parsing --- quartz/plugins/transformers/frontmatter.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/quartz/plugins/transformers/frontmatter.ts b/quartz/plugins/transformers/frontmatter.ts index d50217ba6..26a665d8f 100644 --- a/quartz/plugins/transformers/frontmatter.ts +++ b/quartz/plugins/transformers/frontmatter.ts @@ -49,11 +49,19 @@ export const FrontMatter: QuartzTransformerPlugin | undefined> 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 + .toString() + .split(oneLineTagDelim) + .map((tag: string) => tag.trim()) + } + + // remove all non-string tags data.tags = data.tags - .toString() - .split(oneLineTagDelim) - .map((tag: string) => tag.trim()) + .filter((tag: unknown) => typeof tag === "string" || typeof tag === "number") + .map((tag: string | number) => tag.toString()) } // slug them all!!