Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] v4 from jackyzha0:v4 #39

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions quartz/plugins/transformers/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -37,16 +38,18 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options> | 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)
Expand All @@ -57,11 +60,7 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options> | 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"]
}
},
]
Expand Down