« 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/generateArtistInfoPageTracksChunk.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageTracksChunk.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunk.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
new file mode 100644
index 00000000..b27a2988
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
@@ -0,0 +1,52 @@
+import {stitchArrays} from '#sugar';
+import {getTotalDuration} from '#wiki-data';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunk',
+    'generateArtistInfoPageTracksChunkItem',
+    'linkAlbum',
+  ],
+
+  relations: (relation, artist, album, tracks, contribs) => ({
+    template:
+      relation('generateArtistInfoPageChunk'),
+
+    albumLink:
+      relation('linkAlbum', album),
+
+    items:
+      stitchArrays({
+        track: tracks,
+        contribs: contribs,
+      }).map(({track, contribs}) =>
+          relation('generateArtistInfoPageTracksChunkItem',
+            artist,
+            track,
+            contribs)),
+  }),
+
+  data: (_artist, album, tracks, _contribs) => ({
+    // STUB: This is flat-out incorrect date behavior.
+    date:
+      album.date,
+
+    duration:
+      getTotalDuration(tracks, {originalReleasesOnly: true}),
+
+    durationApproximate:
+      tracks
+        .filter(track => track.duration && track.isOriginalRelease)
+        .length > 1,
+  }),
+
+  generate: (data, relations) =>
+    relations.template.slots({
+      mode: 'album',
+      albumLink: relations.albumLink,
+      date: data.date,
+      duration: data.duration,
+      durationApproximate: data.durationApproximate,
+      items: relations.items,
+    }),
+};