« get me outta code hell

content, data: generateArtistInfoPageMusicVideosChunkedList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-04-14 20:26:02 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-04-14 20:26:02 -0300
commit2336e252d25536d3678119ff070189e666b98927 (patch)
tree788b9c689b8c7ac4324af092c73e95f20b5abd6f /src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js
parented38f9529084cdd3ff6cdfb56148fd9a99c259b2 (diff)
content, data: generateArtistInfoPageMusicVideosChunkedList
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js b/src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js
new file mode 100644
index 00000000..588fbbeb
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageMusicVideosChunkedList.js
@@ -0,0 +1,66 @@
+import {chunkByConditions, stitchArrays} from '#sugar';
+import {sortAlbumsTracksChronologically, sortContributionsChronologically}
+  from '#sort';
+
+export default {
+  query(artist) {
+    const query = {};
+
+    const allContributions = [
+      ...artist.musicVideoArtistContributions,
+      ...artist.musicVideoContributorContributions,
+      ...artist.otherMusicVideoArtistContributionsToOwnAlbums,
+    ];
+
+    const getMusicVideo = contrib =>
+      contrib.thing;
+
+    const getAlbumOrTrack = contrib =>
+      getMusicVideo(contrib).thing;
+
+    sortContributionsChronologically(
+      allContributions,
+      sortAlbumsTracksChronologically,
+      {getThing: getAlbumOrTrack});
+
+    const getAlbum = contrib =>
+      (getAlbumOrTrack(contrib).isTrack
+        ? getAlbumOrTrack(contrib).album
+        : getAlbumOrTrack(contrib));
+
+    query.contribs =
+      chunkByConditions(allContributions, [
+        (a, b) => getAlbum(a) !== getAlbum(b),
+      ]).map(contribs =>
+          chunkByConditions(contribs, [
+            (a, b) => getMusicVideo(a) !== getMusicVideo(b),
+          ]));
+
+    query.albums =
+      query.contribs
+        .map(contribs => contribs[0][0])
+        .map(contrib => getAlbum(contrib));
+
+    return query;
+  },
+
+  relations: (relation, query, artist) => ({
+    template:
+      relation('generateArtistInfoPageChunkedList'),
+
+    chunks:
+      stitchArrays({
+        album: query.albums,
+        contribs: query.contribs,
+      }).map(({album, contribs}) =>
+          relation('generateArtistInfoPageMusicVideosChunk',
+            artist,
+            album,
+            contribs)),
+  }),
+
+  generate: (relations) =>
+    relations.template.slots({
+      chunks: relations.chunks,
+    }),
+};