feat: add note modification date display and sorting

This commit is contained in:
KazooTTT
2025-02-05 23:20:24 +08:00
parent 5056450ca5
commit 4387c9c484
3 changed files with 42 additions and 4 deletions

View File

@ -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();
}