Corrects and simplifies ordering of feed items in blog and links
This commit is contained in:
@@ -27,8 +27,8 @@ function matchesYear(year: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sortByPubDateDescending(post1: CollectionEntry<'blog'>, post2: CollectionEntry<'blog'>) {
|
function sortByPubDateDescending(post1: CollectionEntry<'blog'>, post2: CollectionEntry<'blog'>) {
|
||||||
const date1 = post1.data.pubDate.getMilliseconds();
|
const date1 = post1.data.pubDate.getTime();
|
||||||
const date2 = post2.data.pubDate.getMilliseconds();
|
const date2 = post2.data.pubDate.getTime();
|
||||||
return date2 - date1;
|
return date2 - date1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,20 +29,9 @@ function matchesYear(year: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sortByDateAddedDescending(link1: (typeof links)[number], link2: (typeof links)[number]) {
|
function sortByDateAddedDescending(link1: (typeof links)[number], link2: (typeof links)[number]) {
|
||||||
const year1 = Number.parseInt(link1.isoDateAdded.slice(0, 4));
|
const date1 = new Date(link1.isoDateAdded).getTime();
|
||||||
const year2 = Number.parseInt(link2.isoDateAdded.slice(0, 4));
|
const date2 = new Date(link2.isoDateAdded).getTime();
|
||||||
const month1 = Number.parseInt(link1.isoDateAdded.slice(5, 7));
|
return date2 - date1;
|
||||||
const month2 = Number.parseInt(link2.isoDateAdded.slice(5, 7));
|
|
||||||
const day1 = Number.parseInt(link1.isoDateAdded.slice(8, 10));
|
|
||||||
const day2 = Number.parseInt(link2.isoDateAdded.slice(8, 10));
|
|
||||||
|
|
||||||
if (year1 !== year2) {
|
|
||||||
return year2 - year1;
|
|
||||||
} else if (month1 !== month2) {
|
|
||||||
return month2 - month1;
|
|
||||||
} else {
|
|
||||||
return day2 - day1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const canonicalLinksUrl = new URL('links', Astro.site)
|
const canonicalLinksUrl = new URL('links', Astro.site)
|
||||||
|
|||||||
Reference in New Issue
Block a user