feat: sort libraries by total downloads by default (#1771)

This commit is contained in:
Nikolay Geldyev
2025-03-21 12:55:20 +03:00
committed by GitHub
parent c3b8692960
commit 3fc5b6bb3a
+1 -24
View File
@@ -71,30 +71,7 @@ const sortBy = {
default: { default: {
label: "Default", label: "Default",
func: (items) => { func: (items) => {
const sortedByNewAsc = sortBy.new.func(items); return sortBy.downloadsTotal.func(items);
const TWO_WEEKS = 12096e5;
const timeTwoWeeksAgo = new Date(Date.now() - TWO_WEEKS);
const indexOfItemOlderThan2WeeksAsc =
sortedByNewAsc.length -
sortedByNewAsc
.slice()
.reverse()
.findIndex((x) => {
return new Date(x.created) <= timeTwoWeeksAgo;
});
const topNewItemsAsc = sortedByNewAsc.slice(
indexOfItemOlderThan2WeeksAsc,
);
const downloadPerWeekAsc = sortBy.downloadsWeek.func(
sortedByNewAsc.slice(0, indexOfItemOlderThan2WeeksAsc),
);
return downloadPerWeekAsc.concat(topNewItemsAsc);
}, },
}, },
new: { new: {