« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateScopedTrackChronologyLinks.js89
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js116
2 files changed, 102 insertions, 103 deletions
diff --git a/src/content/dependencies/generateScopedTrackChronologyLinks.js b/src/content/dependencies/generateScopedTrackChronologyLinks.js
deleted file mode 100644
index 87a7c0fd..00000000
--- a/src/content/dependencies/generateScopedTrackChronologyLinks.js
+++ /dev/null
@@ -1,89 +0,0 @@
-import {sortAlbumsTracksChronologically} from '#sort';
-
-import getChronologyRelations from '../util/getChronologyRelations.js';
-
-export default {
-  contentDependencies: [
-    'generateChronologyLinks',
-    'linkAlbum',
-    'linkArtist',
-    'linkTrack',
-  ],
-
-  relations(relation, album, track) {
-    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});
-          },
-        }),
-    };
-  },
-
-  generate: (relations) =>
-    relations.chronologyLinks.slots({
-      showOnly: true,
-
-      chronologyInfoSets: [
-        {
-          headingString: 'misc.chronology.heading.track',
-          contributions: relations.artistChronologyContributions,
-        },
-        {
-          headingString: 'misc.chronology.heading.coverArt',
-          contributions: relations.coverArtistChronologyContributions,
-        },
-      ],
-    }),
-};
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),
       ],
-    }),
+    });
+  },
 };