mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
603c181ad2
* fix: alt error mix with height/width More granular detection of alt and resize in image * fix: format * feat: allow to translate the date displayed * style: format * fix: rename to fusion dateLocale with locale (i18n support) * Update quartz/components/PageList.tsx Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * remove default key as it was already set * add docstring for locale --------- Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
30 lines
863 B
TypeScript
30 lines
863 B
TypeScript
import { GlobalConfiguration } from "../cfg"
|
|
import { QuartzPluginData } from "../plugins/vfile"
|
|
|
|
interface Props {
|
|
date: Date
|
|
locale?: string
|
|
}
|
|
|
|
export type ValidDateType = keyof Required<QuartzPluginData>["dates"]
|
|
|
|
export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): Date | undefined {
|
|
if (!cfg.defaultDateType) {
|
|
throw new Error(
|
|
`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]
|
|
}
|
|
|
|
export function formatDate(d: Date, locale = "en-US"): string {
|
|
return d.toLocaleDateString(locale, {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "2-digit",
|
|
})
|
|
}
|
|
|
|
export function Date({ date, locale }: Props) {
|
|
return <>{formatDate(date, locale)}</>
|
|
}
|