« get me outta code hell

content: generateTrackChronologyLinks: align sort orders - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-23 17:05:35 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:18 -0300
commitbfe389e20902a27f0c2b29eb2abef8fcfe0fc62c (patch)
tree51128849742a11a904e1fc417d7d1cf8a88d46f1 /src
parente2df11974850e3e890d3fdb4573947abc804e505 (diff)
content: generateTrackChronologyLinks: align sort orders
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateChronologyLinks.js3
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js36
-rw-r--r--src/content/util/getChronologyRelations.js4
3 files changed, 33 insertions, 10 deletions
diff --git a/src/content/dependencies/generateChronologyLinks.js b/src/content/dependencies/generateChronologyLinks.js
index b769a5aa..7f24ded7 100644
--- a/src/content/dependencies/generateChronologyLinks.js
+++ b/src/content/dependencies/generateChronologyLinks.js
@@ -21,10 +21,11 @@ export default {
             headingString: v.isString,
             contributions: v.strictArrayOf(v.validateProperties({
               index: v.isCountingNumber,
+              only: v.isBoolean,
+              artistDirectory: v.isDirectory,
               artistLink: v.isHTML,
               previousLink: v.isHTML,
               nextLink: v.isHTML,
-              only: v.isBoolean,
             })),
           })),
     }
diff --git a/src/content/dependencies/generateTrackChronologyLinks.js b/src/content/dependencies/generateTrackChronologyLinks.js
index 15c2cae9..24e56698 100644
--- a/src/content/dependencies/generateTrackChronologyLinks.js
+++ b/src/content/dependencies/generateTrackChronologyLinks.js
@@ -74,16 +74,36 @@ export default {
       };
     }
 
-    return {
-      scopeSwitcher:
-        relation('generateChronologyLinksScopeSwitcher'),
+    const relations = {};
 
-      wiki:
-        getScopedRelations(null),
+    relations.scopeSwitcher =
+      relation('generateChronologyLinksScopeSwitcher');
 
-      album:
-        getScopedRelations(track.album),
-    };
+    relations.wiki =
+      getScopedRelations(null);
+
+    relations.album =
+      getScopedRelations(track.album);
+
+    for (const setKey of [
+      'artistChronologyContributions',
+      'coverArtistChronologyContributions',
+    ]) {
+      const wikiSet = relations.wiki[setKey];
+      const albumSet = relations.album[setKey];
+
+      const wikiArtistDirectories =
+        wikiSet
+          .map(({artistDirectory}) => artistDirectory);
+
+      albumSet.sort((a, b) =>
+        (a.index === b.index
+          ? (wikiArtistDirectories.indexOf(a.artistDirectory)
+           - wikiArtistDirectories.indexOf(b.artistDirectory))
+          : 0));
+    }
+
+    return relations;
   },
 
   generate(relations) {
diff --git a/src/content/util/getChronologyRelations.js b/src/content/util/getChronologyRelations.js
index e4475ff8..c601a990 100644
--- a/src/content/util/getChronologyRelations.js
+++ b/src/content/util/getChronologyRelations.js
@@ -42,10 +42,12 @@ export default function getChronologyRelations(thing, {
 
     return {
       index: index + 1,
+      artistDirectory: artist.directory,
+      only: !(previous || next),
+
       artistLink: linkArtist(artist),
       previousLink: previous ? linkThing(previous) : null,
       nextLink: next ? linkThing(next) : null,
-      only: !(previous || next),
     };
   }).filter(Boolean)
     .sort((a, b) =>