« 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/dependencies/generateTrackChronologyLinks.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateTrackChronologyLinks.js')
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js116
1 files changed, 102 insertions, 14 deletions
diff --git a/src/content/dependencies/generateTrackChronologyLinks.js b/src/content/dependencies/generateTrackChronologyLinks.js
index accb9ef1..fd676942 100644
--- a/src/content/dependencies/generateTrackChronologyLinks.js
+++ b/src/content/dependencies/generateTrackChronologyLinks.js
@@ -1,30 +1,118 @@
+import {sortAlbumsTracksChronologically} from '#sort';
+
+import getChronologyRelations from '../util/getChronologyRelations.js';
+
 export default {
   contentDependencies: [
+    'generateChronologyLinks',
     'generateChronologyLinksScopeSwitcher',
-    'generateScopedTrackChronologyLinks',
+    'linkAlbum',
+    'linkArtist',
+    'linkTrack',
   ],
 
-  relations: (relation, track) => ({
-    scopeSwitcher:
-      relation('generateChronologyLinksScopeSwitcher'),
+  relations(relation, track) {
+    function getScopedRelations(album) {
+      const albumFilter =
+        (album
+          ? track => track.album === album
+          : () => true);
+
+      return {
+        chronologyLinks:
+          relation('generateChronologyLinks'),
+
+        artistChronologyContributions:
+          getChronologyRelations(track, {
+            contributions: [
+              ...track.artistContribs ?? [],
+              ...track.contributorContribs ?? [],
+            ],
+
+            linkArtist: artist => relation('linkArtist', artist),
+            linkThing: track => relation('linkTrack', track),
+
+            getThings(artist) {
+              const getDate = thing => thing.date;
+
+              const things =
+                ([
+                  ...artist.tracksAsArtist,
+                  ...artist.tracksAsContributor,
+                ]).filter(getDate)
+                  .filter(albumFilter);
+
+              return sortAlbumsTracksChronologically(things, {getDate});
+            },
+          }),
+
+        coverArtistChronologyContributions:
+          getChronologyRelations(track, {
+            contributions: track.coverArtistContribs ?? [],
+
+            linkArtist: artist => relation('linkArtist', artist),
+
+            linkThing: trackOrAlbum =>
+              (trackOrAlbum.album
+                ? relation('linkTrack', trackOrAlbum)
+                : relation('linkAlbum', trackOrAlbum)),
+
+            getThings(artist) {
+              const getDate = thing => thing.coverArtDate ?? thing.date;
+
+              const things =
+                ([
+                  ...artist.albumsAsCoverArtist,
+                  ...artist.tracksAsCoverArtist,
+                ]).filter(getDate)
+                  .filter(albumFilter);
+
+              return sortAlbumsTracksChronologically(things, {getDate});
+            },
+          }),
+      };
+    }
+
+    return {
+      scopeSwitcher:
+        relation('generateChronologyLinksScopeSwitcher'),
+
+      wiki:
+        getScopedRelations(null),
+
+      album:
+        getScopedRelations(track.album),
+    };
+  },
 
-    wikiChronologyLinks:
-      relation('generateScopedTrackChronologyLinks', null, track),
+  generate(relations) {
+    function slotScopedRelations(scope) {
+      return scope.chronologyLinks.slots({
+        showOnly: true,
 
-    albumChronologyLinks:
-      relation('generateScopedTrackChronologyLinks', track.album, track),
-  }),
+        chronologyInfoSets: [
+          {
+            headingString: 'misc.chronology.heading.track',
+            contributions: scope.artistChronologyContributions,
+          },
+          {
+            headingString: 'misc.chronology.heading.coverArt',
+            contributions: scope.coverArtistChronologyContributions,
+          },
+        ],
+      });
+    }
 
-  generate: (relations) =>
-    relations.scopeSwitcher.slots({
+    return relations.scopeSwitcher.slots({
       scopes: [
         'wiki',
         'album',
       ],
 
       contents: [
-        relations.wikiChronologyLinks,
-        relations.albumChronologyLinks,
+        slotScopedRelations(relations.wiki),
+        slotScopedRelations(relations.album),
       ],
-    }),
+    });
+  },
 };