mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-23 18:51:30 +08:00
Initial commit
This commit is contained in:
23
src/utils/date.ts
Normal file
23
src/utils/date.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { siteConfig } from "@/site.config";
|
||||
|
||||
export function getFormattedDate(
|
||||
date: Date | undefined,
|
||||
options?: Intl.DateTimeFormatOptions,
|
||||
): string {
|
||||
if (date === undefined) {
|
||||
return "Invalid Date";
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat(siteConfig.date.locale, {
|
||||
...(siteConfig.date.options as Intl.DateTimeFormatOptions),
|
||||
...options,
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
export function collectionDateSort(
|
||||
a: CollectionEntry<"post" | "note">,
|
||||
b: CollectionEntry<"post" | "note">,
|
||||
) {
|
||||
return b.data.publishDate.getTime() - a.data.publishDate.getTime();
|
||||
}
|
Reference in New Issue
Block a user