Skip to content

Commit 1cfc876

Browse files
committed
fix: tz-less date parse in local tz instead of utc (closes #1615)
1 parent 096ef22 commit 1cfc876

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

quartz/plugins/transformers/frontmatter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
101101
const socialImage = coalesceAliases(data, ["socialImage", "image", "cover"])
102102

103103
const created = coalesceAliases(data, ["created", "date"])
104-
if (created) data.created = created
104+
if (created) {
105+
data.created = created
106+
data.modified ||= created // if modified is not set, use created
107+
}
108+
105109
const modified = coalesceAliases(data, [
106110
"modified",
107111
"lastmod",

quartz/plugins/transformers/lastmod.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ const defaultOptions: Options = {
1212
priority: ["frontmatter", "git", "filesystem"],
1313
}
1414

15+
// YYYY-MM-DD
16+
const iso8601DateOnlyRegex = /^\d{4}-\d{2}-\d{2}$/
17+
1518
function coerceDate(fp: string, d: any): Date {
19+
// check ISO8601 date-only format
20+
// we treat this one as local midnight as the normal
21+
// js date ctor treats YYYY-MM-DD as UTC midnight
22+
if (typeof d === "string" && iso8601DateOnlyRegex.test(d)) {
23+
d = `${d}T00:00:00`
24+
}
25+
1626
const dt = new Date(d)
1727
const invalidDate = isNaN(dt.getTime()) || dt.getTime() === 0
1828
if (invalidDate && d !== undefined) {

0 commit comments

Comments
 (0)