« 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/misc-templates.js3
-rw-r--r--src/page/album.js1
-rw-r--r--src/page/artist.js4
-rw-r--r--src/util/wiki-data.js4
4 files changed, 7 insertions, 5 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index d4e4af38..139978d8 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -45,6 +45,7 @@ export function getArtistString(artists, {
 // Chronology links
 
 export function generateChronologyLinks(currentThing, {
+    dateKey = 'date',
     contribKey,
     getThings,
     headingString,
@@ -65,7 +66,7 @@ export function generateChronologyLinks(currentThing, {
     }
 
     return contributions.map(({ who: artist }) => {
-        const things = sortByDate(unique(getThings(artist)));
+        const things = sortByDate(unique(getThings(artist)), dateKey);
         const releasedThings = things.filter(thing => {
             const album = albumData.includes(thing) ? thing : thing.album;
             return !(album && album.directory === UNRELEASED_TRACKS_DIRECTORY);
diff --git a/src/page/album.js b/src/page/album.js
index adcc0584..19efc701 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -394,6 +394,7 @@ export function generateAlbumChronologyLinks(album, currentTrack, {generateChron
         }),
         generateChronologyLinks(currentTrack || album, {
             contribKey: 'coverArtists',
+            dateKey: 'coverArtDate',
             getThings: artist => [...artist.albums.asCoverArtist, ...artist.tracks.asCoverArtist],
             headingString: 'misc.chronology.heading.coverArt'
         })
diff --git a/src/page/artist.js b/src/page/artist.js
index 695fddf0..2e87669d 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -51,7 +51,7 @@ export function write(artist, {wikiData}) {
         key
     });
 
-    const artListChunks = chunkByProperties(artThingsAll.flatMap(thing =>
+    const artListChunks = chunkByProperties(sortByDate(artThingsAll.flatMap(thing =>
         (['coverArtists', 'wallpaperArtists', 'bannerArtists']
             .map(key => getArtistsAndContrib(thing, key))
             .filter(({ contrib }) => contrib)
@@ -61,7 +61,7 @@ export function write(artist, {wikiData}) {
                 date: +(thing.coverArtDate || thing.date),
                 ...props
             })))
-    ), ['date', 'album']);
+    )), ['date', 'album']);
 
     const commentaryListChunks = chunkByProperties(commentaryThings.map(thing => ({
         album: thing.album || thing,
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 87c4b22a..3f24e6a7 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -79,11 +79,11 @@ export function sortByName(a, b) {
 // This function was originally made to sort just al8um data, 8ut its exact
 // code works fine for sorting tracks too, so I made the varia8les and names
 // more general.
-export function sortByDate(data) {
+export function sortByDate(data, dateKey = 'date') {
     // Just to 8e clear: sort is a mutating function! I only return the array
     // 8ecause then you don't have to define it as a separate varia8le 8efore
     // passing it into this function.
-    return data.sort((a, b) => a.date - b.date);
+    return data.sort((a, b) => a[dateKey] - b[dateKey]);
 }
 
 // Same details as the sortByDate, 8ut for covers~