« get me outta code hell

content: generateScopedTrackChronologyLinks - 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 14:10:12 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:16 -0300
commit4b38b2227544db2f0420a22f2880c14857cfbecd (patch)
tree54b93ed02cba4c068a15ca661a09b7a3e723a518 /src
parentfcfe91f9b032740f44de16b41e4a35a90dbbfa78 (diff)
content: generateScopedTrackChronologyLinks
Content in generateTrackChronologyLinks is a stub.
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateScopedTrackChronologyLinks.js87
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js79
2 files changed, 98 insertions, 68 deletions
diff --git a/src/content/dependencies/generateScopedTrackChronologyLinks.js b/src/content/dependencies/generateScopedTrackChronologyLinks.js
new file mode 100644
index 00000000..6fc3f6eb
--- /dev/null
+++ b/src/content/dependencies/generateScopedTrackChronologyLinks.js
@@ -0,0 +1,87 @@
+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({
+      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 814e9a6a..ba4428a5 100644
--- a/src/content/dependencies/generateTrackChronologyLinks.js
+++ b/src/content/dependencies/generateTrackChronologyLinks.js
@@ -1,75 +1,18 @@
-import {sortAlbumsTracksChronologically} from '#sort';
-
-import getChronologyRelations from '../util/getChronologyRelations.js';
-
 export default {
-  contentDependencies: [
-    'generateChronologyLinks',
-    'linkArtist',
-    'linkTrack',
-  ],
+  contentDependencies: ['generateScopedTrackChronologyLinks'],
+  extraDependencies: ['html'],
 
   relations: (relation, track) => ({
-    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);
-
-          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);
+    wikiChronologyLinks:
+      relation('generateScopedTrackChronologyLinks', null, track),
 
-          return sortAlbumsTracksChronologically(things, {getDate});
-        },
-      }),
+    albumChronologyLinks:
+      relation('generateScopedTrackChronologyLinks', track.album, track),
   }),
 
-  generate: (relations) =>
-    relations.chronologyLinks.slots({
-      chronologyInfoSets: [
-        {
-          headingString: 'misc.chronology.heading.track',
-          contributions: relations.artistChronologyContributions,
-        },
-        {
-          headingString: 'misc.chronology.heading.coverArt',
-          contributions: relations.coverArtistChronologyContributions,
-        },
-      ],
-    }),
+  generate: (relations, {html}) =>
+    html.tags([
+      relations.wikiChronologyLinks,
+      relations.albumChronologyLinks,
+    ]),
 };