Skip to content

Commit

Permalink
feat(dates): allow multiple values for defaultDateType config
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
baodrate committed Dec 13, 2024
1 parent 93de138 commit 6cf3b40
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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.
Expand Down
2 changes: 1 addition & 1 deletion quartz.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config: QuartzConfig = {
locale: "en-US",
baseUrl: "quartz.jzhao.xyz",
ignorePatterns: ["private", "templates", ".obsidian"],
defaultDateType: "created",
defaultDateType: ["published", "created"],
generateSocialImages: false,
theme: {
fontOrigin: "googleFonts",
Expand Down
2 changes: 1 addition & 1 deletion quartz/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion quartz/components/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6cf3b40

Please sign in to comment.