« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/page/artist.js2
-rw-r--r--src/util/wiki-data.js14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/page/artist.js b/src/page/artist.js
index 87859c89..29e4aba6 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -40,7 +40,7 @@ export function write(artist, {wikiData}) {
       ...(artist.albumsAsCoverArtist ?? []),
       ...(artist.tracksAsCoverArtist ?? []),
     ],
-    {getDate: (o) => o.coverArtDate});
+    {latestFirst: true, getDate: (o) => o.coverArtDate});
 
   const commentaryThings = sortAlbumsTracksChronologically([
     ...(artist.albumsAsCommentator ?? []),
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 0eb86a1e..5a0e241a 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;
 }