diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 7f0f206e1..153bbe21d 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 254c5d405..5337feed8 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 8713cfd3c..6feac178c 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 eb34f02f7..644e354c4 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 63f040d81..9a53ad7eb 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 7c9b33bbd..1eeb78322 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 : ""}
    `,