From c8332bb4e9b719eae0bc8f758ab1835ea1b4d0e8 Mon Sep 17 00:00:00 2001
From: "(quasar) nebula" <qznebula@protonmail.com>
Date: Fri, 23 Jun 2023 20:01:21 -0300
Subject: content: use stitchArrays in various places

---
 .../dependencies/generateAlbumCommentaryPage.js    | 24 +++++++++++++---------
 .../dependencies/generateAlbumGalleryPage.js       | 20 ++++++++++--------
 .../dependencies/generateArtistGalleryPage.js      | 10 +++++----
 3 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/src/content/dependencies/generateAlbumCommentaryPage.js b/src/content/dependencies/generateAlbumCommentaryPage.js
index 15d43a32..ea31292c 100644
--- a/src/content/dependencies/generateAlbumCommentaryPage.js
+++ b/src/content/dependencies/generateAlbumCommentaryPage.js
@@ -1,3 +1,5 @@
+import {stitchArrays} from '../../util/sugar.js';
+
 export default {
   contentDependencies: [
     'generateAlbumNavAccent',
@@ -127,18 +129,20 @@ export default {
               relations.albumCommentaryContent),
           ],
 
-          relations.trackCommentaryContent.map((commentaryContent, i) => [
-            relations.trackCommentaryHeadings[i]
-              .slots({
+          stitchArrays({
+            heading: relations.trackCommentaryHeadings,
+            link: relations.trackCommentaryLinks,
+            directory: data.trackCommentaryDirectories,
+            content: relations.trackCommentaryContent,
+            colorVariables: relations.trackCommentaryColorVariables,
+          }).map(({heading, link, directory, content, colorVariables}) => [
+              heading.slots({
                 tag: 'h3',
-                id: data.trackCommentaryDirectories[i],
-                title: relations.trackCommentaryLinks[i],
+                id: directory,
+                title: link,
               }),
-
-            html.tag('blockquote',
-              {style: relations.trackCommentaryColorVariables[i]},
-              relations.trackCommentaryContent[i]),
-          ]),
+              html.tag('blockquote', {style: colorVariables}, content),
+            ]),
         ],
 
         navLinkStyle: 'hierarchical',
diff --git a/src/content/dependencies/generateAlbumGalleryPage.js b/src/content/dependencies/generateAlbumGalleryPage.js
index 354c8401..71cd477b 100644
--- a/src/content/dependencies/generateAlbumGalleryPage.js
+++ b/src/content/dependencies/generateAlbumGalleryPage.js
@@ -1,3 +1,5 @@
+import {stitchArrays} from '../../util/sugar.js';
+
 export default {
   contentDependencies: [
     'generateAlbumGalleryInfoLine',
@@ -89,14 +91,16 @@ export default {
               links: relations.links,
               names: data.names,
               images:
-                relations.images.map((image, i) =>
-                  image.slots({
-                    path: data.paths[i],
-                    missingSourceContent:
-                      language.$('misc.albumGalleryGrid.noCoverArt', {
-                        name: data.names[i],
-                      }),
-                  })),
+                stitchArrays({
+                  image: relations.images,
+                  path: data.paths,
+                  name: data.names,
+                }).map(({image, path, name}) =>
+                    image.slots({
+                      path,
+                      missingSourceContent:
+                        language.$('misc.albumGalleryGrid.noCoverArt', {name}),
+                    })),
             }),
         ],
 
diff --git a/src/content/dependencies/generateArtistGalleryPage.js b/src/content/dependencies/generateArtistGalleryPage.js
index 41758d59..d1ec3efe 100644
--- a/src/content/dependencies/generateArtistGalleryPage.js
+++ b/src/content/dependencies/generateArtistGalleryPage.js
@@ -1,3 +1,4 @@
+import {stitchArrays} from '../../util/sugar.js';
 import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js';
 
 // TODO: Very awkward we have to duplicate this functionality in relations and data.
@@ -92,10 +93,11 @@ export default {
               links: relations.links,
               names: data.names,
               images:
-                relations.images.map((image, i) =>
-                  image.slots({
-                    path: data.paths[i],
-                  })),
+                stitchArrays({
+                  image: relations.images,
+                  path: data.paths,
+                }).map(({image, path}) =>
+                    image.slot('path', path)),
             }),
         ],
 
-- 
cgit 1.3.0-6-gf8a5