Skip to content

Commit

Permalink
chore(frontmatter): dealias created/modified/updated time (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm authored Dec 23, 2024
1 parent ff9e60a commit 965f9e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 15 additions & 0 deletions quartz/plugins/transformers/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)

const socialImage = coalesceAliases(data, ["socialImage", "image", "cover"])

const created = coalesceAliases(data, ["created", "date"])
if (created) data.created = created
const modified = coalesceAliases(data, [
"modified",
"lastmod",
"updated",
"last-modified",
])
if (modified) data.modified = modified
const published = coalesceAliases(data, ["published", "publishDate", "date"])
if (published) data.published = published

if (socialImage) data.socialImage = socialImage

// fill in frontmatter
Expand All @@ -91,6 +103,9 @@ declare module "vfile" {
} & Partial<{
tags: string[]
aliases: string[]
modified: string
created: string
published: string
description: string
publish: boolean | string
draft: boolean | string
Expand Down
8 changes: 3 additions & 5 deletions quartz/plugins/transformers/lastmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
created ||= st.birthtimeMs
modified ||= st.mtimeMs
} else if (source === "frontmatter" && file.data.frontmatter) {
created ||= file.data.frontmatter.date as MaybeDate
modified ||= file.data.frontmatter.lastmod as MaybeDate
modified ||= file.data.frontmatter.updated as MaybeDate
modified ||= file.data.frontmatter["last-modified"] as MaybeDate
published ||= file.data.frontmatter.publishDate as MaybeDate
created ||= file.data.frontmatter.created as MaybeDate
modified ||= file.data.frontmatter.modified as MaybeDate
published ||= file.data.frontmatter.published as MaybeDate
} else if (source === "git") {
if (!repo) {
// Get a reference to the main git repo.
Expand Down

0 comments on commit 965f9e1

Please sign in to comment.