« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js145
-rw-r--r--src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js94
-rw-r--r--src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js42
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js103
4 files changed, 250 insertions, 134 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
index a7293eb5..36daf9c4 100644
--- a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
@@ -24,58 +24,105 @@ export default {
     // shape (#70) and get their own sorting function. Read for more info:
     // https://github.com/hsmusic/hsmusic-wiki/issues/90#issuecomment-1607422961
 
-    const processEntries = (things, details) =>
-      things.map(thing => ({
-        thing,
-        entry: details(thing),
-      }));
+    const processEntry = ({thing, type, track, album, contribs}) => ({
+      thing: thing,
+      entry: {
+        type: type,
+        track: track,
+        album: album,
+        contribs: contribs,
+        date: thing.coverArtDate ?? thing.date,
+      },
+    });
 
-    const albumCoverEntries =
-      processEntries(
-        artist.albumsAsCoverArtist,
-        album => ({
-          type: 'albumCover',
-          album: album,
-          date: album.coverArtDate ?? album.date,
-          contribs: album.coverArtistContribs,
-        }));
-
-    const albumWallpaperEntries =
-      processEntries(
-        artist.albumsAsWallpaperArtist,
-        album => ({
-          type: 'albumWallpaper',
-          album: album,
-          date: album.coverArtDate ?? album.date,
-          contribs: album.wallpaperArtistContribs,
-        }));
-
-    const albumBannerEntries =
-      processEntries(
-        artist.albumsAsBannerArtist,
-        album => ({
-          type: 'albumBanner',
-          album: album,
-          date: album.coverArtDate ?? album.date,
-          contribs: album.bannerArtistContribs,
-        }));
-
-    const trackCoverEntries =
-      processEntries(
-        artist.tracksAsCoverArtist,
-        track => ({
-          type: 'trackCover',
-          album: track.album,
-          date: track.coverArtDate ?? track.date,
-          track: track,
-          contribs: track.coverArtistContribs,
-        }));
+    const processAlbumEntry = ({type, album, contribs}) =>
+      processEntry({
+        thing: album,
+        type: type,
+        track: null,
+        album: album,
+        contribs: contribs,
+      });
+
+    const processTrackEntry = ({type, track, contribs}) =>
+      processEntry({
+        thing: track,
+        type: type,
+        track: track,
+        album: track.album,
+        contribs: contribs,
+      });
+
+    const processAlbumEntries = ({type, albums, contribs}) =>
+      stitchArrays({
+        album: albums,
+        contribs: contribs,
+      }).map(entry =>
+          processAlbumEntry({type, ...entry}));
+
+    const processTrackEntries = ({type, tracks, contribs}) =>
+      stitchArrays({
+        track: tracks,
+        contribs: contribs,
+      }).map(entry =>
+          processTrackEntry({type, ...entry}));
+
+    const {
+      albumsAsCoverArtist,
+      albumsAsWallpaperArtist,
+      albumsAsBannerArtist,
+      tracksAsCoverArtist,
+    } = artist;
+
+    const albumsAsCoverArtistContribs =
+      albumsAsCoverArtist
+        .map(album => album.coverArtistContribs);
+
+    const albumsAsWallpaperArtistContribs =
+      albumsAsWallpaperArtist
+        .map(album => album.wallpaperArtistContribs);
+
+    const albumsAsBannerArtistContribs =
+      albumsAsBannerArtist
+        .map(album => album.bannerArtistContribs);
+
+    const tracksAsCoverArtistContribs =
+      tracksAsCoverArtist
+        .map(track => track.coverArtistContribs);
+
+    const albumsAsCoverArtistEntries =
+      processAlbumEntries({
+        type: 'albumCover',
+        albums: albumsAsCoverArtist,
+        contribs: albumsAsCoverArtistContribs,
+      });
+
+    const albumsAsWallpaperArtistEntries =
+      processAlbumEntries({
+        type: 'albumWallpaper',
+        albums: albumsAsWallpaperArtist,
+        contribs: albumsAsWallpaperArtistContribs,
+      });
+
+    const albumsAsBannerArtistEntries =
+      processAlbumEntries({
+        type: 'albumBanner',
+        albums: albumsAsBannerArtist,
+        contribs: albumsAsBannerArtistContribs,
+      });
+
+    const tracksAsCoverArtistEntries =
+      processTrackEntries({
+        type: 'trackCover',
+        tracks: tracksAsCoverArtist,
+        contribs: tracksAsCoverArtistContribs,
+      });
 
     const entries = [
-      ...albumCoverEntries,
-      ...albumWallpaperEntries,
-      ...albumBannerEntries,
-      ...trackCoverEntries,
+      ...albumsAsCoverArtistEntries,
+      ...albumsAsWallpaperArtistEntries,
+      ...albumsAsBannerArtistEntries,
+      ...tracksAsCoverArtistEntries,
     ];
 
     sortEntryThingPairs(entries,
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,
diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
index ca0d0b50..75a1d05a 100644
--- a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
@@ -16,23 +16,35 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
-    const processEntries = (things, details) =>
-      things.map(thing => ({
-        thing,
-        entry: details(thing),
-      }));
-
-    const contributorEntries =
-      processEntries(
-        artist.flashesAsContributor,
-        flash => ({
-          flash,
-          act: flash.act,
-          contribs: flash.contributorContribs,
-        }));
+    const processFlashEntry = ({flash, contribs}) => ({
+      thing: flash,
+      entry: {
+        flash: flash,
+        act: flash.act,
+        contribs: contribs,
+      },
+    });
+
+    const processFlashEntries = ({flashes, contribs}) =>
+      stitchArrays({
+        flash: flashes,
+        contribs: contribs,
+      }).map(processFlashEntry);
+
+    const {flashesAsContributor} = artist;
+
+    const flashesAsContributorContribs =
+      flashesAsContributor
+        .map(flash => flash.contributorContribs);
+
+    const flashesAsContributorEntries =
+      processFlashEntries({
+        flashes: flashesAsContributor,
+        contribs: flashesAsContributorContribs,
+      });
 
     const entries = [
-      ...contributorEntries,
+      ...flashesAsContributorEntries,
     ];
 
     sortEntryThingPairs(entries, sortFlashesChronologically);
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index cd96b376..a8209165 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -19,58 +19,73 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
-    const processEntries = (things, details) =>
-      things.map(thing => ({
-        thing,
-        entry: details(thing),
-      }));
+    const processTrackEntry = ({track, contribs}) => ({
+      thing: track,
+      entry: {
+        track: track,
+        album: track.album,
+        date: track.date,
+        contribs: contribs,
+      },
+    });
+
+    const processTrackEntries = ({tracks, contribs}) =>
+      stitchArrays({
+        track: tracks,
+        contribs: contribs,
+      }).map(processTrackEntry);
+
+    const {tracksAsArtist, tracksAsContributor} = artist;
 
     const tracksAsArtistAndContributor =
-      artist.tracksAsArtist
-        .filter(track => artist.tracksAsContributor.includes(track));
+      tracksAsArtist
+        .filter(track => tracksAsContributor.includes(track));
 
     const tracksAsArtistOnly =
-      artist.tracksAsArtist
-        .filter(track => !artist.tracksAsContributor.includes(track));
+      tracksAsArtist
+        .filter(track => !tracksAsContributor.includes(track));
 
     const tracksAsContributorOnly =
-      artist.tracksAsContributor
-        .filter(track => !artist.tracksAsArtist.includes(track));
-
-    const entriesAsArtistAndContributor =
-      processEntries(
-        tracksAsArtistAndContributor,
-        track => ({
-          track,
-          album: track.album,
-          date: track.date,
-          contribs: [...track.artistContribs, ...track.contributorContribs],
-        }));
-
-    const entriesAsArtistOnly =
-      processEntries(
-        tracksAsArtistOnly,
-        track => ({
-          track,
-          album: track.album,
-          date: track.date,
-          contribs: track.artistContribs,
-        }));
-
-    const entriesAsContributorOnly =
-      processEntries(
-        tracksAsContributorOnly,
-        track => ({
-          track,
-          date: track.date,
-          album: track.album,
-          contribs: track.contributorContribs,
-        }));
+      tracksAsContributor
+        .filter(track => !tracksAsArtist.includes(track));
+
+    const tracksAsArtistAndContributorContribs =
+      tracksAsArtistAndContributor
+        .map(track => [
+          ...track.artistContribs,
+          ...track.contributorContribs,
+        ]);
+
+    const tracksAsArtistOnlyContribs =
+      tracksAsArtistOnly
+        .map(track => track.artistContribs);
+
+    const tracksAsContributorOnlyContribs =
+      tracksAsContributorOnly
+        .map(track => track.contributorContribs);
+
+    const tracksAsArtistAndContributorEntries =
+      processTrackEntries({
+        tracks: tracksAsArtistAndContributor,
+        contribs: tracksAsArtistAndContributorContribs,
+      });
+
+    const tracksAsArtistOnlyEntries =
+      processTrackEntries({
+        tracks: tracksAsArtistOnly,
+        contribs: tracksAsArtistOnlyContribs,
+      });
+
+    const tracksAsContributorOnlyEntries =
+      processTrackEntries({
+        tracks: tracksAsContributorOnly,
+        contribs: tracksAsContributorOnlyContribs,
+      });
 
     const entries = [
-      ...entriesAsArtistAndContributor,
-      ...entriesAsArtistOnly,
-      ...entriesAsContributorOnly,
+      ...tracksAsArtistAndContributorEntries,
+      ...tracksAsArtistOnlyEntries,
+      ...tracksAsContributorOnlyEntries,
     ];
 
     sortEntryThingPairs(entries, sortAlbumsTracksChronologically);