feat(dates): allow configurable default timezone

This commit is contained in:
Bao Trinh 2024-12-05 03:49:08 -06:00
parent 5f6788cada
commit 0b7dafd852
No known key found for this signature in database
GPG Key ID: 66B50C2AD65984B2
2 changed files with 10 additions and 1 deletions

View File

@ -12,6 +12,7 @@ This plugin determines the created, modified, and published dates for a document
This plugin accepts the following configuration options:
- `priority`: The data sources to consult for date information. Highest priority first. Possible values are `"frontmatter"`, `"git"`, and `"filesystem"`. Defaults to `["frontmatter", "git", "filesystem"]`.
- `defaultTimezone`: The timezone that is assumed (IANA format, e.g. `Africa/Algiers`) when the datetime frontmatter properties do not contain offsets/timezones. Defaults to `system`: the system's local timezone.
> [!warning]
> If you rely on `git` for dates, make sure `defaultDateType` is set to `modified` in `quartz.config.ts`.

View File

@ -7,10 +7,17 @@ import chalk from "chalk"
export interface Options {
priority: ("frontmatter" | "git" | "filesystem")[]
/**
* The default timezone used when parsing datetime strings which lack an offset/timezone
* Valid options are "system" (default), "utc", an IANA string, or a UTC offset
* https://moment.github.io/luxon/#/zones?id=specifying-a-zone
*/
defaultTimezone: "system" | string
}
const defaultOptions: Options = {
priority: ["frontmatter", "git", "filesystem"],
defaultTimezone: "system",
}
function parseDateString(
@ -55,8 +62,9 @@ function parseDateString(
export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
const opts = { ...defaultOptions, ...userOpts }
const parseOpts = {
const parseOpts: DateTimeOptions = {
setZone: true,
zone: opts.defaultTimezone,
}
return {
name: "CreatedModifiedDate",