« 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/generateArtistInfoPageCommentaryChunkedList.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js94
1 files changed, 68 insertions, 26 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
index dad1585a..7c2418b1 100644
--- a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
@@ -19,34 +19,76 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
-    const processEntries = (things, details) =>
-      things.flatMap(thing =>
-        thing.commentary
-          .filter(entry => entry.artists.includes(artist))
-          .map(entry => ({
-            thing,
-            entry: {
-              annotation: entry.annotation,
-              ...details(thing, entry),
-            },
-          })));
-
-    const albumEntries =
-      processEntries(
-        artist.albumsAsCommentator,
-        album => ({
-          type: 'album',
-          album,
-        }));
+    const processEntry = ({thing, entry, type, track, album}) => ({
+      thing: thing,
+      entry: {
+        type: type,
+        track: track,
+        album: album,
+        annotation: entry.annotation,
+      },
+    });
+
+    const processAlbumEntry = ({type, album, entry}) =>
+      processEntry({
+        thing: album,
+        entry: entry,
+        type: type,
+        album: album,
+        track: null,
+      });
+
+    const processTrackEntry = ({type, track, entry}) =>
+      processEntry({
+        thing: track,
+        entry: entry,
+        type: type,
+        album: track.album,
+        track: track,
+      });
+
+    const processEntries = ({things, processEntry}) =>
+      things
+        .flatMap(thing =>
+          thing.commentary
+            .filter(entry => entry.artists.includes(artist))
+            .map(entry => processEntry({thing, entry})));
+
+    const processAlbumEntries = ({type, albums}) =>
+      processEntries({
+        things: albums,
+        processEntry: ({thing, entry}) =>
+          processAlbumEntry({
+            type: type,
+            album: thing,
+            entry: entry,
+          }),
+      });
+
+    const processTrackEntries = ({type, tracks}) =>
+      processEntries({
+        things: tracks,
+        processEntry: ({thing, entry}) =>
+          processTrackEntry({
+            type: type,
+            track: thing,
+            entry: entry,
+          }),
+      });
+
+    const {albumsAsCommentator, tracksAsCommentator} = artist;
 
     const trackEntries =
-      processEntries(
-        artist.tracksAsCommentator,
-        track => ({
-          type: 'track',
-          album: track.album,
-          track,
-        }));
+      processTrackEntries({
+        type: 'track',
+        tracks: tracksAsCommentator,
+      });
+
+    const albumEntries =
+      processAlbumEntries({
+        type: 'album',
+        albums: albumsAsCommentator,
+      });
 
     const entries = [
       ...albumEntries,