« get me outta code hell

sort art galleries reverse-chronologically (again) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/wiki-data.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-27 15:39:55 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-27 15:39:55 -0300
commit878a96cb223783ef1b100fdb3bb9d795404c44f5 (patch)
tree955e9a4bc2c6efcab315205a98fe19bf82e0212b /src/util/wiki-data.js
parent7233eeffbbb5fe02113ea7e18322eaeec520f79e (diff)
sort art galleries reverse-chronologically (again)
Fixes #170.
Diffstat (limited to 'src/util/wiki-data.js')
-rw-r--r--src/util/wiki-data.js14
1 files changed, 13 insertions, 1 deletions
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;
 }