« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateAlbumInfoPage.js13
-rw-r--r--src/content/dependencies/generateTrackInfoPage.js24
-rw-r--r--src/content/util/getChronologyRelations.js13
3 files changed, 35 insertions, 15 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js
index 26aa4376..7fbe4e23 100644
--- a/src/content/dependencies/generateAlbumInfoPage.js
+++ b/src/content/dependencies/generateAlbumInfoPage.js
@@ -54,13 +54,16 @@ export default {
             ? relation('linkTrack', trackOrAlbum)
             : relation('linkAlbum', trackOrAlbum)),
 
-        getThings: artist =>
-          sortAlbumsTracksChronologically([
+        getThings(artist) {
+          const getDate = thing => thing.coverArtDate ?? thing.date;
+
+          const things = [
             ...artist.albumsAsCoverArtist,
             ...artist.tracksAsCoverArtist,
-          ], {
-            getDate: thing => thing.coverArtDate ?? thing.date,
-          }),
+          ].filter(getDate);
+
+          return sortAlbumsTracksChronologically(things, {getDate});
+        },
       });
 
     relations.albumNavAccent =
diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js
index ef38ba6b..9cce744b 100644
--- a/src/content/dependencies/generateTrackInfoPage.js
+++ b/src/content/dependencies/generateTrackInfoPage.js
@@ -64,11 +64,16 @@ export default {
         linkArtist: artist => relation('linkArtist', artist),
         linkThing: track => relation('linkTrack', track),
 
-        getThings: artist =>
-          sortAlbumsTracksChronologically([
+        getThings(artist) {
+          const getDate = thing => thing.date;
+
+          const things = [
             ...artist.tracksAsArtist,
             ...artist.tracksAsContributor,
-          ]),
+          ].filter(getDate);
+
+          return sortAlbumsTracksChronologically(things, {getDate});
+        },
       });
 
     relations.coverArtistChronologyContributions =
@@ -82,13 +87,16 @@ export default {
             ? relation('linkTrack', trackOrAlbum)
             : relation('linkAlbum', trackOrAlbum)),
 
-        getThings: artist =>
-          sortAlbumsTracksChronologically([
+        getThings(artist) {
+          const getDate = thing => thing.coverArtDate ?? thing.date;
+
+          const things = [
             ...artist.albumsAsCoverArtist,
             ...artist.tracksAsCoverArtist,
-          ], {
-            getDate: thing => thing.coverArtDate ?? thing.date,
-          }),
+          ].filter(getDate);
+
+          return sortAlbumsTracksChronologically(things, {getDate});
+        },
       }),
 
     relations.albumLink =
diff --git a/src/content/util/getChronologyRelations.js b/src/content/util/getChronologyRelations.js
index 036c5586..67d6d5fa 100644
--- a/src/content/util/getChronologyRelations.js
+++ b/src/content/util/getChronologyRelations.js
@@ -29,13 +29,22 @@ export default function getChronologyRelations(thing, {
 
   return contributions.map(({who}) => {
     const things = Array.from(new Set(getThings(who)));
-    if (things.length === 1) {
+
+    // Don't show a line if this contribution isn't part of the artist's
+    // chronology at all (usually because this thing isn't dated).
+    const index = things.indexOf(thing);
+    if (index === -1) {
       return;
     }
 
-    const index = things.indexOf(thing);
+    // Don't show a line if this contribution is the *only* item in the
+    // artist's chronology (since there's nothing to navigate there).
     const previous = things[index - 1];
     const next = things[index + 1];
+    if (!previous && !next) {
+      return;
+    }
+
     return {
       index: index + 1,
       artistLink: linkArtist(who),