mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-22 18:21:31 +08:00
feat: add note modification date display and sorting
This commit is contained in:
@ -21,3 +21,23 @@ export function collectionDateSort(
|
||||
) {
|
||||
return b.data.date.getTime() - a.data.date.getTime();
|
||||
}
|
||||
|
||||
const datePriorityForNote = ["date_modified", "date", "data_created"];
|
||||
|
||||
export function collectionModifiedDateSort(
|
||||
a: CollectionEntry<"post" | "note">,
|
||||
b: CollectionEntry<"post" | "note">,
|
||||
) {
|
||||
let dateA: Date = new Date(),
|
||||
dateB: Date = new Date();
|
||||
datePriorityForNote.forEach((key) => {
|
||||
if (a.data[key as keyof typeof a.data]) {
|
||||
dateA = a.data[key as keyof typeof a.data] as Date;
|
||||
}
|
||||
if (b.data[key as keyof typeof b.data]) {
|
||||
dateB = b.data[key as keyof typeof b.data] as Date;
|
||||
}
|
||||
});
|
||||
|
||||
return dateB.getTime() - dateA.getTime();
|
||||
}
|
||||
|
Reference in New Issue
Block a user