« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateAlbumInfoPage.js62
-rw-r--r--src/content/dependencies/generateReleaseInfoContributionsLine.js49
-rw-r--r--src/content/dependencies/generateTrackInfoPage.js48
3 files changed, 92 insertions, 67 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js
index 1e8fa194..e317adb1 100644
--- a/src/content/dependencies/generateAlbumInfoPage.js
+++ b/src/content/dependencies/generateAlbumInfoPage.js
@@ -16,11 +16,11 @@ export default {
     'generateColorStyleRules',
     'generateContentHeading',
     'generatePageLayout',
+    'generateReleaseInfoContributionsLine',
     'linkAlbum',
     'linkAlbumCommentary',
     'linkAlbumGallery',
     'linkArtist',
-    'linkContribution',
     'linkExternal',
     'linkTrack',
     'transformContent',
@@ -71,37 +71,26 @@ export default {
     relations.sidebar =
       relation('generateAlbumSidebar', album, null);
 
-    const contributionLinksRelation = contribs =>
-      contribs.map(contrib =>
-        relation('linkContribution', contrib.who, contrib.what));
+    if (album.hasCoverArt) {
+      relations.cover =
+        relation('generateAlbumCoverArtwork', album);
+    }
 
     // Section: Release info
 
     const releaseInfo = sections.releaseInfo = {};
 
-    if (!empty(album.artistContribs)) {
-      releaseInfo.artistContributionLinks =
-        contributionLinksRelation(album.artistContribs);
-    }
+    releaseInfo.artistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.artistContribs);
 
-    if (album.hasCoverArt) {
-      relations.cover =
-        relation('generateAlbumCoverArtwork', album);
-      releaseInfo.coverArtistContributionLinks =
-        contributionLinksRelation(album.coverArtistContribs);
-    } else {
-      relations.cover = null;
-    }
+    releaseInfo.coverArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.coverArtistContribs);
 
-    if (album.hasWallpaperArt) {
-      releaseInfo.wallpaperArtistContributionLinks =
-        contributionLinksRelation(album.wallpaperArtistContribs);
-    }
+    releaseInfo.wallpaperArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.wallpaperArtistContribs);
 
-    if (album.hasBannerArt) {
-      releaseInfo.bannerArtistContributionLinks =
-        contributionLinksRelation(album.bannerArtistContribs);
-    }
+    releaseInfo.bannerArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.bannerArtistContribs);
 
     // Section: Listen on
 
@@ -189,16 +178,6 @@ export default {
   generate(data, relations, {html, language}) {
     const {sections: sec} = relations;
 
-    const formatContributions =
-      (stringKey, contributionLinks, {showContribution = true, showIcons = true} = {}) =>
-        contributionLinks &&
-          language.$(stringKey, {
-            artists:
-              language.formatConjunctionList(
-                contributionLinks.map(link =>
-                  link.slots({showContribution, showIcons}))),
-          });
-
     return relations.layout
       .slots({
         title: language.$('albumPage.title', {album: data.name}),
@@ -221,10 +200,17 @@ export default {
               [html.joinChildren]: html.tag('br'),
             },
             [
-              formatContributions('releaseInfo.by', sec.releaseInfo.artistContributionLinks),
-              formatContributions('releaseInfo.coverArtBy', sec.releaseInfo.coverArtistContributionLinks),
-              formatContributions('releaseInfo.wallpaperArtBy', sec.releaseInfo.wallpaperArtistContributionLinks),
-              formatContributions('releaseInfo.bannerArtBy', sec.releaseInfo.bannerArtistContributionLinks),
+              sec.releaseInfo.artistContributionsLine
+                .slots({stringKey: 'releaseInfo.by'}),
+
+              sec.releaseInfo.coverArtistContributionsLine
+                .slots({stringKey: 'releaseInfo.coverArtBy'}),
+
+              sec.releaseInfo.wallpaperArtistContributionsLine
+                .slots({stringKey: 'releaseInfo.wallpaperArtBy'}),
+
+              sec.releaseInfo.bannerArtistContributionsLine
+                .slots({stringKey: 'releasInfo.bannerArtBy'}),
 
               data.date &&
                 language.$('releaseInfo.released', {
diff --git a/src/content/dependencies/generateReleaseInfoContributionsLine.js b/src/content/dependencies/generateReleaseInfoContributionsLine.js
new file mode 100644
index 00000000..2b342d09
--- /dev/null
+++ b/src/content/dependencies/generateReleaseInfoContributionsLine.js
@@ -0,0 +1,49 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['linkContribution'],
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, contributions) {
+    if (empty(contributions)) {
+      return {};
+    }
+
+    return {
+      contributionLinks:
+        contributions
+          .slice(0, 4)
+          .map(({who, what}) =>
+            relation('linkContribution', who, what)),
+    };
+  },
+
+  generate(relations, {html, language}) {
+    return html.template({
+      annotation: `generateReleaseInfoContributionsLine`,
+
+      slots: {
+        stringKey: {type: 'string'},
+
+        showContribution: {type: 'boolean', default: true},
+        showIcons: {type: 'boolean', default: true},
+      },
+
+      content(slots) {
+        if (!relations.contributionLinks) {
+          return html.blank();
+        }
+
+        return language.$(slots.stringKey, {
+          artists:
+            language.formatConjunctionList(
+              relations.contributionLinks.map(link =>
+                link.slots({
+                  showContribution: slots.showContribution,
+                  showIcons: slots.showIcons,
+                }))),
+        });
+      },
+    });
+  },
+};
diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js
index 745e367e..ed28edec 100644
--- a/src/content/dependencies/generateTrackInfoPage.js
+++ b/src/content/dependencies/generateTrackInfoPage.js
@@ -18,6 +18,7 @@ export default {
     'generateColorStyleRules',
     'generateContentHeading',
     'generatePageLayout',
+    'generateReleaseInfoContributionsLine',
     'generateTrackCoverArtwork',
     'generateTrackList',
     'generateTrackListDividedByGroups',
@@ -102,12 +103,6 @@ export default {
     relations.sidebar =
       relation('generateAlbumSidebar', track.album, track);
 
-    const contributionLinksRelation = contribs =>
-      contribs
-        .slice(0, 4)
-        .map(contrib =>
-          relation('linkContribution', contrib.who, contrib.what));
-
     const additionalFilesSection = additionalFiles => ({
       heading: relation('generateContentHeading'),
       list: relation('generateAlbumAdditionalFilesList', album, additionalFiles),
@@ -123,11 +118,11 @@ export default {
     const releaseInfo = sections.releaseInfo = {};
 
     releaseInfo.artistContributionLinks =
-      contributionLinksRelation(track.artistContribs);
+      relation('generateReleaseInfoContributionsLine', track.artistContribs);
 
     if (track.hasUniqueCoverArt) {
-      releaseInfo.coverArtistContributionLinks =
-        contributionLinksRelation(track.coverArtistContribs);
+      releaseInfo.coverArtistContributionsLine =
+        relation('generateReleaseInfoContributionsLine', track.coverArtistContribs);
     }
 
     // Section: Listen on
@@ -173,7 +168,8 @@ export default {
         relation('generateContentHeading');
 
       contributors.contributionLinks =
-        contributionLinksRelation(track.contributorContribs);
+        track.contributorContribs.map(({who, what}) =>
+          relation('linkContribution', who, what));
     }
 
     // Section: Referenced tracks
@@ -341,16 +337,6 @@ export default {
   generate(data, relations, {html, language}) {
     const {sections: sec} = relations;
 
-    const formatContributions =
-      (stringKey, contributionLinks, {showContribution = true, showIcons = true} = {}) =>
-        contributionLinks &&
-          language.$(stringKey, {
-            artists:
-              language.formatConjunctionList(
-                contributionLinks.map(link =>
-                  link.slots({showContribution, showIcons}))),
-          });
-
     return relations.layout
       .slots({
         title: language.$('trackPage.title', {track: data.name}),
@@ -371,8 +357,11 @@ export default {
             [html.onlyIfContent]: true,
             [html.joinChildren]: html.tag('br'),
           }, [
-            formatContributions('releaseInfo.by', sec.releaseInfo.artistContributionLinks),
-            formatContributions('releaseInfo.coverArtBy', sec.releaseInfo.coverArtistContributionLinks),
+            sec.releaseInfo.artistContributionLinks
+              .slots({stringKey: 'releaseInfo.by'}),
+
+            sec.releaseInfo.coverArtistContributionsLine
+              ?.slots({stringKey: 'releaseInfo.coverArtBy'}),
 
             data.date &&
               language.$('releaseInfo.released', {
@@ -453,13 +442,14 @@ export default {
                 title: language.$('releaseInfo.contributors'),
               }),
 
-            html.tag('ul', sec.contributors.contributionLinks.map(contributionLink =>
-              html.tag('li',
-                contributionLink
-                  .slots({
-                    showIcons: true,
-                    showContribution: true,
-                  })))),
+            html.tag('ul',
+              sec.contributors.contributionLinks.map(contributionLink =>
+                html.tag('li',
+                  contributionLink
+                    .slots({
+                      showIcons: true,
+                      showContribution: true,
+                    })))),
           ],
 
           sec.references && [