« get me outta code hell

content: generateAlbumChronologyLinks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumChronologyLinks.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-12 14:50:11 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:09 -0300
commitdc0b29d087aa335a8ffd97f7cbe1f22b2f115f09 (patch)
tree9127353a118b4727c72dd266d48776777bd108d1 /src/content/dependencies/generateAlbumChronologyLinks.js
parent50869c28f76cd05c37ce4c5c2f56f52277397c59 (diff)
content: generateAlbumChronologyLinks
Diffstat (limited to 'src/content/dependencies/generateAlbumChronologyLinks.js')
-rw-r--r--src/content/dependencies/generateAlbumChronologyLinks.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/content/dependencies/generateAlbumChronologyLinks.js b/src/content/dependencies/generateAlbumChronologyLinks.js
new file mode 100644
index 00000000..3dd7a18e
--- /dev/null
+++ b/src/content/dependencies/generateAlbumChronologyLinks.js
@@ -0,0 +1,53 @@
+import {sortAlbumsTracksChronologically} from '#sort';
+
+import getChronologyRelations from '../util/getChronologyRelations.js';
+
+export default {
+  contentDependencies: [
+    'generateChronologyLinks',
+    'linkAlbum',
+    'linkArtist',
+    'linkTrack',
+  ],
+
+  relations: (relation, album) => ({
+    chronologyLinks:
+      relation('generateChronologyLinks'),
+
+    coverArtistChronologyContributions:
+      getChronologyRelations(album, {
+        contributions: album.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.albumCoverArtistContributions,
+              artist.trackCoverArtistContributions,
+            ]).flat()
+              .map(({thing}) => thing)
+              .filter(getDate);
+
+          return sortAlbumsTracksChronologically(things, {getDate});
+        },
+      }),
+  }),
+
+  generate: (relations) =>
+    relations.chronologyLinks.slots({
+      chronologyInfoSets: [
+        {
+          headingString: 'misc.chronology.heading.coverArt',
+          contributions: relations.coverArtistChronologyContributions,
+        },
+      ],
+    }),
+}