From 5f6788cadab7d2f4be3b0f27b80b9a8d5e9c4ae3 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Tue, 3 Dec 2024 17:25:48 -0600 Subject: [PATCH] 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` --- docs/configuration.md | 1 + quartz/cfg.ts | 2 +- quartz/components/Date.tsx | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 1622da6fa..2e904e9e7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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]() 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. diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 135f58499..0c755b741 100644 --- a/quartz/cfg.ts +++ b/quartz/cfg.ts @@ -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 */ diff --git a/quartz/components/Date.tsx b/quartz/components/Date.tsx index a75d02859..783a86f01 100644 --- a/quartz/components/Date.tsx +++ b/quartz/components/Date.tsx @@ -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 {