« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/util/getChronologyRelations.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/util/getChronologyRelations.js')
-rw-r--r--src/content/util/getChronologyRelations.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/content/util/getChronologyRelations.js b/src/content/util/getChronologyRelations.js
index 67d6d5fa..c601a990 100644
--- a/src/content/util/getChronologyRelations.js
+++ b/src/content/util/getChronologyRelations.js
@@ -18,17 +18,17 @@ export default function getChronologyRelations(thing, {
 
   const artistsSoFar = new Set();
 
-  contributions = contributions.filter(({who}) => {
-    if (artistsSoFar.has(who)) {
+  contributions = contributions.filter(({artist}) => {
+    if (artistsSoFar.has(artist)) {
       return false;
     } else {
-      artistsSoFar.add(who);
+      artistsSoFar.add(artist);
       return true;
     }
   });
 
-  return contributions.map(({who}) => {
-    const things = Array.from(new Set(getThings(who)));
+  return contributions.map(({artist}) => {
+    const things = Array.from(new Set(getThings(artist)));
 
     // 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).
@@ -37,19 +37,21 @@ export default function getChronologyRelations(thing, {
       return;
     }
 
-    // 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),
+      artistDirectory: artist.directory,
+      only: !(previous || next),
+
+      artistLink: linkArtist(artist),
       previousLink: previous ? linkThing(previous) : null,
       nextLink: next ? linkThing(next) : null,
     };
-  }).filter(Boolean);
+  }).filter(Boolean)
+    .sort((a, b) =>
+      (a.only === b.only ?  b.index - a.index
+     : a.only            ? +1
+                         : -1))
 }