Skip to content

Commit

Permalink
feat(dates): allow configurable default timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
baodrate committed Dec 22, 2024
1 parent 5a37d7c commit 729b84c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/plugins/CreatedModifiedDate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]`.
- `timezone`: The timezone that is assumed (IANA format, e.g. `Africa/Abidjan`) when one is not specified in the datetime frontmatter properties. 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`.
Expand Down
10 changes: 10 additions & 0 deletions quartz/plugins/transformers/lastmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ import { DateTime, DateTimeOptions } from "luxon"
import { Repository } from "@napi-rs/simple-git"
import { QuartzTransformerPlugin } from "../types"
import chalk from "chalk"
import { Settings as LuxonSettings } from "luxon/src/settings"

export interface Options {
priority: ("frontmatter" | "git" | "filesystem")[]
/**
* The default timezone when handling dates.
* Valid options are "system" (default), "utc", an IANA string, or a UTC offset
* https://moment.github.io/luxon/#/zones?id=specifying-a-zone
*/
timezone: "system" | string
}

const defaultOptions: Options = {
priority: ["frontmatter", "git", "filesystem"],
timezone: "system",
}

function parseDateString(fp: string, d: string | number | unknown): DateTime<true> | undefined {
Expand Down Expand Up @@ -51,6 +59,8 @@ function parseDateString(fp: string, d: string | number | unknown): DateTime<tru

export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
const opts = { ...defaultOptions, ...userOpts }
// note that this will affect the behavior of Luxon globally
LuxonSettings.defaultZone = opts.timezone
return {
name: "CreatedModifiedDate",
markdownPlugins() {
Expand Down

0 comments on commit 729b84c

Please sign in to comment.