feat(dates): allow multiple values for defaultDateType config

Allows the user to set fallback values for the `defaultDateType` setting

Prior to this commit, if the date was not set, it would default to the
current time. e.g. if using `defaultDateType == "published"` or if
the CreatedModifiedDate plugin's `priority` setting is set without
`filesystem`
This commit is contained in:
Bao Trinh 2024-12-03 17:25:48 -06:00
parent 52a2f32273
commit 5f6788cada
No known key found for this signature in database
GPG Key ID: 66B50C2AD65984B2
3 changed files with 4 additions and 2 deletions

View File

@ -40,6 +40,7 @@ This part of the configuration concerns anything that can affect the whole site.
- Note that Quartz 4 will avoid using this as much as possible and use relative URLs whenever it can to make sure your site works no matter _where_ you end up actually deploying it.
- `ignorePatterns`: a list of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that Quartz should ignore and not search through when looking for files inside the `content` folder. See [[private pages]] for more details.
- `defaultDateType`: whether to use created, modified, or published as the default date to display on pages and page listings.
- Can be a list (e.g. `["created", "modified"]`) to define fallbacks (highest priority first).
- `theme`: configure how the site looks.
- `cdnCaching`: If `true` (default), use Google CDN to cache the fonts. This will generally will be faster. Disable (`false`) this if you want Quartz to download the fonts to be self-contained.
- `typography`: what fonts to use. Any font available on [Google Fonts](https://fonts.google.com/) works here.

View File

@ -56,7 +56,7 @@ export interface GlobalConfiguration {
/** Glob patterns to not search */
ignorePatterns: string[]
/** Whether to use created, modified, or published as the default type of date */
defaultDateType: ValidDateType
defaultDateType: ValidDateType | ValidDateType[]
/** Base URL to use for CNAME files, sitemaps, and RSS feeds that require an absolute URL.
* Quartz will avoid using this as much as possible and use relative URLs most of the time
*/

View File

@ -16,7 +16,8 @@ export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): DateT
`Field 'defaultDateType' was not set in the configuration object of quartz.config.ts. See https://quartz.jzhao.xyz/configuration#general-configuration for more details.`,
)
}
return data.dates?.[cfg.defaultDateType]
const types = cfg.defaultDateType instanceof Array ? cfg.defaultDateType : [cfg.defaultDateType]
return types.map((p) => data.dates?.[p]).find((p) => p != null)
}
export function formatDate(d: DateTime, locale: ValidLocale = "en-US"): string {