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

chore(frontmatter): dealias created/modified/updated time #1664

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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",
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
"updated",
"last-modified",
])
if (modified) data.modified = modified
const published = coalesceAliases(data, ["publishDate", "published", "date"])
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
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
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
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
Loading