« get me outta code hell

content: gAIP{*}ChunkedList: stub processEntries refactor - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-02-06 09:56:50 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-06 09:56:50 -0400
commitc876fa2573d877f60198b24259d6908a1e775239 (patch)
treee14961ec0a6b73cfcccb4074bed2a39a085737f5
parent10f57c4bbc5fc84d57c32c85a1dae55873088973 (diff)
content: gAIP{*}ChunkedList: stub processEntries refactor
-rw-r--r--src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js53
-rw-r--r--src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js31
-rw-r--r--src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js20
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js42
4 files changed, 92 insertions, 54 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
index a3bcf687..9efd2b14 100644
--- a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
@@ -24,47 +24,58 @@ 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 entries = [
-      ...artist.albumsAsCoverArtist.map(album => ({
-        thing: album,
-        entry: {
+    const processEntries = (things, details) =>
+      things.map(thing => ({
+        thing,
+        entry: details(thing),
+      }));
+
+    const albumCoverEntries =
+      processEntries(
+        artist.albumsAsCoverArtist,
+        album => ({
           type: 'albumCover',
           album: album,
           date: album.coverArtDate ?? album.date,
           contribs: album.coverArtistContribs,
-        },
-      })),
+        }));
 
-      ...artist.albumsAsWallpaperArtist.map(album => ({
-        thing: album,
-        entry: {
+    const albumWallpaperEntries =
+      processEntries(
+        artist.albumsAsWallpaperArtist,
+        album => ({
           type: 'albumWallpaper',
           album: album,
           date: album.coverArtDate ?? album.date,
           contribs: album.wallpaperArtistContribs,
-        },
-      })),
+        }));
 
-      ...artist.albumsAsBannerArtist.map(album => ({
-        thing: album,
-        entry: {
+    const albumBannerEntries =
+      processEntries(
+        artist.albumsAsBannerArtist,
+        album => ({
           type: 'albumBanner',
           album: album,
           date: album.coverArtDate ?? album.date,
           contribs: album.bannerArtistContribs,
-        },
-      })),
+        }));
 
-      ...artist.tracksAsCoverArtist.map(track => ({
-        thing: track,
-        entry: {
+    const trackCoverEntries =
+      processEntries(
+        artist.tracksAsCoverArtist,
+        track => ({
           type: 'trackCover',
           album: track.album,
           date: track.coverArtDate ?? track.date,
           track: track,
           contribs: track.coverArtistContribs,
-        },
-      })),
+        }));
+
+    const entries = [
+      ...albumCoverEntries,
+      ...albumWallpaperEntries,
+      ...albumBannerEntries,
+      ...trackCoverEntries,
     ];
 
     sortEntryThingPairs(entries,
diff --git a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
index af5a923f..2892152e 100644
--- a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
@@ -18,23 +18,32 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
-    const entries = [
-      ...artist.albumsAsCommentator.map(album => ({
-        thing: album,
-        entry: {
+    const processEntries = (things, details) =>
+      things.map(thing => ({
+        thing,
+        entry: details(thing),
+      }));
+
+    const albumEntries =
+      processEntries(
+        artist.albumsAsCommentator,
+        album => ({
           type: 'album',
           album,
-        },
-      })),
+        }));
 
-      ...artist.tracksAsCommentator.map(track => ({
-        thing: track,
-        entry: {
+    const trackEntries =
+      processEntries(
+        artist.tracksAsCommentator,
+        track => ({
           type: 'track',
           album: track.album,
           track,
-        },
-      })),
+        }));
+
+    const entries = [
+      ...albumEntries,
+      ...trackEntries,
     ];
 
     sortEntryThingPairs(entries, sortAlbumsTracksChronologically);
diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
index 799e8509..8f02ef9b 100644
--- a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
@@ -16,15 +16,23 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
-    const entries = [
-      ...artist.flashesAsContributor.map(flash => ({
-        thing: flash,
-        entry: {
+    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 entries = [
+      ...contributorEntries,
     ];
 
     sortEntryThingPairs(entries, sortFlashesChronologically);
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index 654f759c..4ad047b9 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -19,6 +19,12 @@ export default {
   extraDependencies: ['html', 'language'],
 
   query(artist) {
+    const processEntries = (things, details) =>
+      things.map(thing => ({
+        thing,
+        entry: details(thing),
+      }));
+
     const tracksAsArtistAndContributor =
       artist.tracksAsArtist
         .filter(track => artist.tracksAsContributor.includes(track));
@@ -31,36 +37,40 @@ export default {
       artist.tracksAsContributor
         .filter(track => !artist.tracksAsArtist.includes(track));
 
-    const entries = [
-      ...tracksAsArtistAndContributor.map(track => ({
-        thing: track,
-        entry: {
+    const entriesAsArtistAndContributor =
+      processEntries(
+        tracksAsArtistAndContributor,
+        track => ({
           track,
           album: track.album,
           date: track.date,
           contribs: [...track.artistContribs, ...track.contributorContribs],
-        },
-      })),
+        }));
 
-      ...tracksAsArtistOnly.map(track => ({
-        thing: track,
-        entry: {
+    const entriesAsArtistOnly =
+      processEntries(
+        tracksAsArtistOnly,
+        track => ({
           track,
           album: track.album,
           date: track.date,
           contribs: track.artistContribs,
-        },
-      })),
+        }));
 
-      ...tracksAsContributorOnly.map(track => ({
-        thing: track,
-        entry: {
+    const entriesAsContributorOnly =
+      processEntries(
+        tracksAsContributorOnly,
+        track => ({
           track,
           date: track.date,
           album: track.album,
           contribs: track.contributorContribs,
-        },
-      })),
+        }));
+
+    const entries = [
+      ...entriesAsArtistAndContributor,
+      ...entriesAsArtistOnly,
+      ...entriesAsContributorOnly,
     ];
 
     sortEntryThingPairs(entries, sortAlbumsTracksChronologically);