diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 7f0f206..153bbe2 100644 --- a/quartz/cfg.ts +++ b/quartz/cfg.ts @@ -35,6 +35,12 @@ export interface GlobalConfiguration { */ baseUrl?: string theme: Theme + /** + * The locale to use for date formatting. Default to "en-US" + * Allow to translate the date in the language of your choice. + * Need to be formated following the IETF language tag format (https://en.wikipedia.org/wiki/IETF_language_tag) + */ + locale?: string } export interface QuartzConfig { diff --git a/quartz/components/ContentMeta.tsx b/quartz/components/ContentMeta.tsx index 254c5d4..5337fee 100644 --- a/quartz/components/ContentMeta.tsx +++ b/quartz/components/ContentMeta.tsx @@ -24,7 +24,7 @@ export default ((opts?: Partial) => { const segments: string[] = [] if (fileData.dates) { - segments.push(formatDate(getDate(cfg, fileData)!)) + segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale)) } // Display reading time if enabled diff --git a/quartz/components/Date.tsx b/quartz/components/Date.tsx index 8713cfd..6feac17 100644 --- a/quartz/components/Date.tsx +++ b/quartz/components/Date.tsx @@ -3,6 +3,7 @@ import { QuartzPluginData } from "../plugins/vfile" interface Props { date: Date + locale?: string } export type ValidDateType = keyof Required["dates"] @@ -16,14 +17,14 @@ export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): Date return data.dates?.[cfg.defaultDateType] } -export function formatDate(d: Date): string { - return d.toLocaleDateString("en-US", { +export function formatDate(d: Date, locale = "en-US"): string { + return d.toLocaleDateString(locale, { year: "numeric", month: "short", day: "2-digit", }) } -export function Date({ date }: Props) { - return <>{formatDate(date)} +export function Date({ date, locale }: Props) { + return <>{formatDate(date, locale)} } diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index eb34f02..644e354 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -46,7 +46,7 @@ export function PageList({ cfg, fileData, allFiles, limit }: Props) {
{page.dates && (

- +

)}
diff --git a/quartz/components/RecentNotes.tsx b/quartz/components/RecentNotes.tsx index 63f040d..9a53ad7 100644 --- a/quartz/components/RecentNotes.tsx +++ b/quartz/components/RecentNotes.tsx @@ -47,7 +47,7 @@ export default ((userOpts?: Partial) => {
{page.dates && (

- +

)}
    diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index 7c9b33b..1eeb783 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -441,7 +441,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin value: `
    -
    ${callouts[calloutType] ?? callouts.note}
    +
    ${callouts[calloutType] ?? callouts.note}
    ${title}
    ${collapse ? toggleIcon : ""}
    `,