« get me outta code hell

content: gAIP{*}ChunkedList: much more aggressive refactor - 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:
author(quasar) nebula <qznebula@protonmail.com>2024-02-06 11:20:27 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-06 11:20:27 -0400
commitddc3465fb48c540360fba977a59be9a5a3a49c04 (patch)
treea11efa0a103a1ae4bfdc0107813f8ea427a884aa /src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
parentbb3fbea9b650d79c4ca797524818ea7893c74570 (diff)
content: gAIP{*}ChunkedList: much more aggressive refactor
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 dad1585..7c2418b 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,