From 878a96cb223783ef1b100fdb3bb9d795404c44f5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 27 Apr 2023 15:39:55 -0300 Subject: sort art galleries reverse-chronologically (again) Fixes #170. --- src/util/wiki-data.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/util/wiki-data.js') diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 0eb86a1..5a0e241 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -316,6 +316,7 @@ export function sortChronologically(data, { // // This function also works for data lists which contain only tracks. export function sortAlbumsTracksChronologically(data, { + latestFirst = false, getDate, } = {}) { // Sort albums before tracks... @@ -333,7 +334,18 @@ export function sortAlbumsTracksChronologically(data, { // released on the same date, they'll still be grouped together by album, // and tracks within an album will retain their relative positioning (i.e. // stay in the same order as part of the album's track listing). - sortByDate(data, {getDate}); + + if (latestFirst) { + // Like in sortChronologically, double reverse: Since we reverse after + // sorting by date, also reverse before, so that items with the same date + // are flipped relative to each other twice - that maintains the original + // relative ordering! + data.reverse(); + sortByDate(data, {getDate}); + data.reverse(); + } else { + sortByDate(data, {getDate}); + } return data; } -- cgit 1.3.0-6-gf8a5