« get me outta code hell

content: multiline content & fill out album/track pages more - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumInfoPageContent.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-25 22:08:35 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-25 22:08:35 -0300
commit22ca57c7fd366ff6ca055ec5c28f527e57509bb8 (patch)
tree9f976a06b14b59902505c6c68eaf6db2d7fbc8ae /src/content/dependencies/generateAlbumInfoPageContent.js
parent6d8fe82b5386af536ca96eb1d89150e201c603e9 (diff)
content: multiline content & fill out album/track pages more
Diffstat (limited to 'src/content/dependencies/generateAlbumInfoPageContent.js')
-rw-r--r--src/content/dependencies/generateAlbumInfoPageContent.js186
1 files changed, 113 insertions, 73 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPageContent.js b/src/content/dependencies/generateAlbumInfoPageContent.js
index 76862f9c..7b8522b7 100644
--- a/src/content/dependencies/generateAlbumInfoPageContent.js
+++ b/src/content/dependencies/generateAlbumInfoPageContent.js
@@ -13,65 +13,104 @@ export default {
     'linkExternal',
   ],
 
-  extraDependencies: [
-    'html',
-    'language',
-    'transformMultiline',
-  ],
+  extraDependencies: ['html', 'language'],
 
   relations(relation, album) {
     const relations = {};
+    const sections = relations.sections = {};
 
     const contributionLinksRelation = contribs =>
       contribs.map(contrib =>
         relation('linkContribution', contrib.who, contrib.what));
 
+    // Section: Release info
+
+    const releaseInfo = sections.releaseInfo = {};
+
+    if (!empty(album.artistContribs)) {
+      releaseInfo.artistContributionLinks =
+        contributionLinksRelation(album.artistContribs);
+    }
+
     if (album.hasCoverArt) {
       relations.cover =
         relation('generateCoverArtwork', album.artTags);
+      releaseInfo.coverArtistContributionLinks =
+        contributionLinksRelation(album.coverArtistContribs);
+    } else {
+      relations.cover = null;
     }
 
-    relations.artistLinks =
-      contributionLinksRelation(album.artistContribs);
+    if (album.hasWallpaperArt) {
+      releaseInfo.wallpaperArtistContributionLinks =
+        contributionLinksRelation(album.wallpaperArtistContribs);
+    }
+
+    if (album.hasBannerArt) {
+      releaseInfo.bannerArtistContributionLinks =
+        contributionLinksRelation(album.bannerArtistContribs);
+    }
+
+    // Section: Listen on
+
+    if (!empty(album.urls)) {
+      const listen = sections.listen = {};
 
-    relations.coverArtistLinks =
-      contributionLinksRelation(album.coverArtistContribs);
+      listen.heading =
+        relation('generateContentHeading');
+
+      listen.externalLinks =
+        album.urls.map(url =>
+          relation('linkExternal', url, {type: 'album'}));
+    }
 
-    relations.wallpaperArtistLinks =
-      contributionLinksRelation(album.wallpaperArtistContribs);
+    // Section: Extra links
 
-    relations.bannerArtistLinks =
-      contributionLinksRelation(album.bannerArtistContribs);
+    const extra = sections.extra = {};
 
     if (album.tracks.some(t => t.hasUniqueCoverArt)) {
-      relations.galleryLink =
+      extra.galleryLink =
         relation('linkAlbumGallery', album);
     }
 
     if (album.commentary || album.tracks.some(t => t.commentary)) {
-      relations.commentaryLink =
+      extra.commentaryLink =
         relation('linkAlbumCommentary', album);
     }
 
-    relations.externalLinks =
-      album.urls.map(url =>
-        relation('linkExternal', url, {type: 'album'}));
+    if (!empty(album.additionalFiles)) {
+      extra.additionalFilesShortcut =
+        relation('generateAdditionalFilesShortcut', album.additionalFiles);
+    }
+
+    // Section: Track list
+
+    relations.trackList =
+      relation('generateAlbumTrackList', album);
 
-    relations.trackList = relation('generateAlbumTrackList', album);
+    // Section: Additional files
 
     if (!empty(album.additionalFiles)) {
-      relations.additionalFilesShortcut =
-        relation('generateAdditionalFilesShortcut', album.additionalFiles);
+      const additionalFiles = sections.additionalFiles = {};
 
-      relations.additionalFilesHeading =
+      additionalFiles.heading =
         relation('generateContentHeading');
 
-      relations.additionalFilesList =
-        relation('generateAlbumAdditionalFilesList', album);
+      additionalFiles.additionalFilesList =
+        relation('generateAlbumAdditionalFilesList', album, album.additionalFiles);
     }
 
-    relations.artistCommentaryHeading =
-      relation('generateContentHeading');
+    // Section: Artist commentary
+
+    if (album.commentary) {
+      const artistCommentary = sections.artistCommentary = {};
+
+      artistCommentary.heading =
+        relation('generateContentHeading');
+
+      artistCommentary.content =
+        relation('transformContent', album.commentary);
+    }
 
     return relations;
   },
@@ -99,7 +138,6 @@ export default {
     }
 
     data.dateAddedToWiki = album.dateAddedToWiki;
-    data.artistCommentary = album.commentary;
 
     return data;
   },
@@ -107,18 +145,20 @@ export default {
   generate(data, relations, {
     html,
     language,
-    transformMultiline,
   }) {
     const content = {};
 
-    const formatContributions = contributionLinks =>
-      language.formatConjunctionList(
-        contributionLinks.map(link =>
-          link
-            .slots({
-              showContribution: true,
-              showIcons: true,
-            })));
+    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}))),
+          });
 
     if (data.hasCoverArt) {
       content.cover = relations.cover
@@ -126,6 +166,8 @@ export default {
           path: ['media.albumCover', data.coverArtDirectory, data.coverArtFileExtension],
           alt: language.$('misc.alt.trackCover')
         });
+    } else {
+      content.cover = null;
     }
 
     content.main = {
@@ -137,25 +179,10 @@ export default {
             [html.joinChildren]: html.tag('br'),
           },
           [
-            !empty(relations.artistLinks) &&
-              language.$('releaseInfo.by', {
-                artists: formatContributions(relations.artistLinks),
-              }),
-
-            !empty(relations.coverArtistLinks) &&
-              language.$('releaseInfo.coverArtBy', {
-                artists: formatContributions(relations.coverArtistLinks),
-              }),
-
-            !empty(relations.wallpaperArtistLinks) &&
-              language.$('releaseInfo.wallpaperArtBy', {
-                artists: formatContributions(relations.wallpaperArtistLinks),
-              }),
-
-            !empty(relations.bannerArtistLinks) &&
-              language.$('releaseInfo.bannerArtBy', {
-                artists: formatContributions(relations.bannerArtistLinks),
-              }),
+            formatContributions('releaseInfo.by', sec.releaseInfo.artistContributionLinks),
+            formatContributions('releaseInfo.coverArtBy', sec.releaseInfo.coverArtistContributionLinks),
+            formatContributions('releaseInfo.wallpaperArtBy', sec.releaseInfo.wallpaperArtistContributionLinks),
+            formatContributions('releaseInfo.bannerArtBy', sec.releaseInfo.bannerArtistContributionLinks),
 
             data.date &&
               language.$('releaseInfo.released', {
@@ -176,35 +203,48 @@ export default {
               }),
           ]),
 
+        sec.listen &&
+          sec.listen.heading.slots({
+            id: 'listen-on',
+            title:
+              language.$('releaseInfo.listenOn', {
+                links: language.formatDisjunctionList(sec.listen.externalLinks),
+              }),
+          }),
+
         html.tag('p',
           {
             [html.onlyIfContent]: true,
             [html.joinChildren]: html.tag('br'),
           },
           [
-            relations.additionalFilesShortcut,
+            sec.extra.additionalFilesShortcut,
+
+            sec.extra.galleryLink && sec.extra.commentaryLink &&
+              language.$('releaseInfo.viewGalleryOrCommentary', {
+                gallery:
+                  sec.extra.galleryLink
+                    .slot('content', language.$('releaseInfo.viewGalleryOrCommentary.gallery')),
+                commentary:
+                  sec.extra.commentaryLink
+                    .slot('content', language.$('releaseInfo.viewGalleryOrCommentary.commentary')),
+              }),
 
-            relations.galleryLink &&
+            sec.extra.galleryLink && !sec.extra.commentaryLink &&
               language.$('releaseInfo.viewGallery', {
                 link:
-                  relations.galleryLink
+                  sec.extra.galleryLink
                     .slot('content', language.$('releaseInfo.viewGallery.link')),
               }),
 
-            relations.commentaryLink &&
+            !sec.extra.galleryLink && sec.extra.commentaryLink &&
               language.$('releaseInfo.viewCommentary', {
                 link:
-                  relations.commentaryLink
+                  sec.extra.commentaryLink
                     .slot('content', language.$('releaseInfo.viewCommentary.link')),
               }),
           ]),
 
-        !empty(relations.externalLinks) &&
-          html.tag('p',
-            language.$('releaseInfo.listenOn', {
-              links: language.formatDisjunctionList(relations.externalLinks),
-            })),
-
         relations.trackList,
 
         html.tag('p',
@@ -219,11 +259,10 @@ export default {
               }),
           ]),
 
-        relations.additionalFilesList && [
-          relations.additionalFilesHeading
+        sec.additionalFiles && [
+          sec.additionalFiles.heading
             .slots({
               id: 'additional-files',
-
               title:
                 language.$('releaseInfo.additionalFiles.heading', {
                   additionalFiles:
@@ -231,18 +270,19 @@ export default {
                 }),
             }),
 
-          relations.additionalFilesList,
+          sec.additionalFiles.additionalFilesList,
         ],
 
-        data.artistCommentary && [
-          relations.artistCommentaryHeading
+        sec.artistCommentary && [
+          sec.artistCommentary.heading
             .slots({
               id: 'artist-commentary',
               title: language.$('releaseInfo.artistCommentary')
             }),
 
           html.tag('blockquote',
-            transformMultiline(data.artistCommentary)),
+            sec.artistCommentary.content
+              .slot('mode', 'multiline')),
         ],
       ]),
     };