diff --git a/quartz/plugins/transformers/frontmatter.ts b/quartz/plugins/transformers/frontmatter.ts index 6498a070c17ed..22b1cc6ec4710 100644 --- a/quartz/plugins/transformers/frontmatter.ts +++ b/quartz/plugins/transformers/frontmatter.ts @@ -4,6 +4,7 @@ import { QuartzTransformerPlugin } from "../types" import yaml from "js-yaml" import toml from "toml" import { slugTag } from "../../util/path" +import { QuartzPluginData } from "../vfile" export interface Options { delims: string | string[] @@ -37,16 +38,18 @@ export const FrontMatter: QuartzTransformerPlugin | undefined> }) // tag is an alias for tags - if (data.tag !== null) { - data.tags = data.tag.toString() + if (data.tag) { + data.tags = data.tag } // coerce title to string - if (data.title !== null) { + if (data.title) { data.title = data.title.toString() + } else if (data.title === null || data.title === undefined) { + data.title = file.stem ?? "Untitled" } - if (data.tags !== null && !Array.isArray(data.tags)) { + if (data.tags && !Array.isArray(data.tags)) { data.tags = data.tags .toString() .split(oneLineTagDelim) @@ -57,11 +60,7 @@ export const FrontMatter: QuartzTransformerPlugin | undefined> data.tags = [...new Set(data.tags?.map((tag: string) => slugTag(tag)))] ?? [] // fill in frontmatter - file.data.frontmatter = { - title: file.stem ?? "Untitled", - tags: [], - ...data, - } + file.data.frontmatter = data as QuartzPluginData["frontmatter"] } }, ]