« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateAlbumInfoPage.js328
1 files changed, 147 insertions, 181 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js
index 1d0f6549..9e4b8816 100644
--- a/src/content/dependencies/generateAlbumInfoPage.js
+++ b/src/content/dependencies/generateAlbumInfoPage.js
@@ -1,5 +1,3 @@
-import {empty} from '#sugar';
-
 export default {
   contentDependencies: [
     'generateAlbumAdditionalFilesList',
@@ -16,219 +14,187 @@ export default {
     'generateCommentarySection',
     'generateContentHeading',
     'generatePageLayout',
-    'linkAlbum',
     'linkAlbumCommentary',
     'linkAlbumGallery',
-    'linkTrack',
-    'transformContent',
   ],
 
   extraDependencies: ['html', 'language'],
 
-  relations(relation, album) {
-    const relations = {};
-    const sections = relations.sections = {};
-
-    relations.layout =
-      relation('generatePageLayout');
-
-    relations.albumStyleRules =
-      relation('generateAlbumStyleRules', album, null);
-
-    relations.socialEmbed =
-      relation('generateAlbumSocialEmbed', album);
-
-    relations.albumNavAccent =
-      relation('generateAlbumNavAccent', album, null);
-
-    relations.chronologyLinks =
-      relation('generateAlbumChronologyLinks', album);
-
-    relations.secondaryNav =
-      relation('generateAlbumSecondaryNav', album);
-
-    relations.sidebar =
-      relation('generateAlbumSidebar', album, null);
-
-    if (album.hasCoverArt) {
-      relations.cover =
-        relation('generateAlbumCoverArtwork', album);
-    }
-
-    if (album.hasBannerArt) {
-      relations.banner =
-        relation('generateAlbumBanner', album);
-    }
-
-    // Section: Release info
+  relations: (relation, album) => ({
+    layout:
+      relation('generatePageLayout'),
 
-    relations.releaseInfo =
-      relation('generateAlbumReleaseInfo', album);
+    albumStyleRules:
+      relation('generateAlbumStyleRules', album, null),
 
-    // Section: Extra links
+    socialEmbed:
+      relation('generateAlbumSocialEmbed', album),
 
-    const extra = sections.extra = {};
+    albumNavAccent:
+      relation('generateAlbumNavAccent', album, null),
 
-    if (album.tracks.some(t => t.hasUniqueCoverArt)) {
-      extra.galleryLink =
-        relation('linkAlbumGallery', album);
-    }
+    chronologyLinks:
+      relation('generateAlbumChronologyLinks', album),
 
-    if (album.commentary || album.tracks.some(t => t.commentary)) {
-      extra.commentaryLink =
-        relation('linkAlbumCommentary', album);
-    }
+    secondaryNav:
+      relation('generateAlbumSecondaryNav', album),
 
-    // Section: Track list
+    sidebar:
+      relation('generateAlbumSidebar', album, null),
 
-    relations.trackList =
-      relation('generateAlbumTrackList', album);
+    cover:
+      (album.hasCoverArt
+        ? relation('generateAlbumCoverArtwork', album)
+        : null),
 
-    // Section: Additional files
+    banner:
+      (album.hasBannerArt
+        ? relation('generateAlbumBanner', album)
+        : null),
 
-    if (!empty(album.additionalFiles)) {
-      const additionalFiles = sections.additionalFiles = {};
+    contentHeading:
+      relation('generateContentHeading'),
 
-      additionalFiles.heading =
-        relation('generateContentHeading');
+    releaseInfo:
+      relation('generateAlbumReleaseInfo', album),
 
-      additionalFiles.additionalFilesList =
-        relation('generateAlbumAdditionalFilesList', album, album.additionalFiles);
-    }
+    galleryLink:
+      (album.tracks.some(t => t.hasUniqueCoverArt)
+        ? relation('linkAlbumGallery', album)
+        : null),
 
-    // Section: Artist commentary
+    commentaryLink:
+      (album.commentary || album.tracks.some(t => t.commentary)
+        ? relation('linkAlbumCommentary', album)
+        : null),
 
-    if (album.commentary) {
-      sections.artistCommentary =
-        relation('generateCommentarySection', album.commentary);
-    }
+    trackList:
+      relation('generateAlbumTrackList', album),
 
-    return relations;
-  },
+    additionalFilesList:
+      relation('generateAlbumAdditionalFilesList',
+        album,
+        album.additionalFiles),
 
-  data(album) {
-    const data = {};
+    artistCommentarySection:
+      relation('generateCommentarySection', album.commentary),
+  }),
 
-    data.name = album.name;
-    data.color = album.color;
+  data: (album) => ({
+    name:
+      album.name,
 
-    if (!empty(album.additionalFiles)) {
-      data.numAdditionalFiles = album.additionalFiles.length;
-    }
+    color:
+      album.color,
 
-    data.dateAddedToWiki = album.dateAddedToWiki;
+    dateAddedToWiki:
+      album.dateAddedToWiki,
+  }),
 
-    return data;
-  },
+  generate: (data, relations, {html, language}) =>
+    relations.layout.slots({
+      title: language.$('albumPage.title', {album: data.name}),
+      headingMode: 'sticky',
 
-  generate(data, relations, {html, language}) {
-    const {sections: sec} = relations;
+      color: data.color,
+      styleRules: [relations.albumStyleRules],
 
-    return relations.layout
-      .slots({
-        title: language.$('albumPage.title', {album: data.name}),
-        headingMode: 'sticky',
+      cover:
+        relations.cover
+          ?.slots({
+            alt: language.$('misc.alt.albumCover'),
+          })
+          ?? null,
 
-        color: data.color,
-        styleRules: [relations.albumStyleRules],
+      mainContent: [
+        relations.releaseInfo,
 
-        cover:
-          relations.cover
-            ?.slots({
-              alt: language.$('misc.alt.albumCover'),
-            })
-            ?? null,
+        html.tag('p',
+          {[html.onlyIfContent]: true},
+          {[html.joinChildren]: html.tag('br')},
 
-        mainContent: [
-          relations.releaseInfo,
-
-          html.tag('p',
-            {[html.onlyIfContent]: true},
-            {[html.joinChildren]: html.tag('br')},
-
-            [
-              sec.additionalFiles &&
-                language.$('releaseInfo.additionalFiles.shortcut', {
-                  link: html.tag('a',
-                    {href: '#additional-files'},
-                    language.$('releaseInfo.additionalFiles.shortcut.link')),
-                }),
-
-              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')),
-                }),
-
-              sec.extra.galleryLink && !sec.extra.commentaryLink &&
-                language.$('releaseInfo.viewGallery', {
-                  link:
-                    sec.extra.galleryLink
-                      .slot('content', language.$('releaseInfo.viewGallery.link')),
-                }),
-
-              !sec.extra.galleryLink && sec.extra.commentaryLink &&
-                language.$('releaseInfo.viewCommentary', {
-                  link:
-                    sec.extra.commentaryLink
-                      .slot('content', language.$('releaseInfo.viewCommentary.link')),
-                }),
-            ]),
-
-          relations.trackList,
-
-          html.tag('p',
-            {[html.onlyIfContent]: true},
-            {[html.joinChildren]: html.tag('br')},
-
-            [
-              language.$('releaseInfo.addedToWiki', {
-                [language.onlyIfOptions]: ['date'],
-                date: language.formatDate(data.dateAddedToWiki),
+          [
+            !html.isBlank(relations.additionalFilesList) &&
+              language.$('releaseInfo.additionalFiles.shortcut', {
+                link: html.tag('a',
+                  {href: '#additional-files'},
+                  language.$('releaseInfo.additionalFiles.shortcut.link')),
               }),
-            ]),
 
-          sec.additionalFiles && [
-            sec.additionalFiles.heading
-              .slots({
-                attributes: {id: 'additional-files'},
-                title: language.$('releaseInfo.additionalFiles.heading'),
+            relations.galleryLink && relations.commentaryLink &&
+              language.$('releaseInfo.viewGalleryOrCommentary', {
+                gallery:
+                  relations.galleryLink
+                    .slot('content', language.$('releaseInfo.viewGalleryOrCommentary.gallery')),
+                commentary:
+                  relations.commentaryLink
+                    .slot('content', language.$('releaseInfo.viewGalleryOrCommentary.commentary')),
               }),
 
-            sec.additionalFiles.additionalFilesList,
-          ],
-
-          sec.artistCommentary,
-        ],
-
-        navLinkStyle: 'hierarchical',
-        navLinks: [
-          {auto: 'home'},
-          {
-            auto: 'current',
-            accent:
-              relations.albumNavAccent.slots({
-                showTrackNavigation: true,
-                showExtraLinks: true,
+            relations.galleryLink && !relations.commentaryLink &&
+              language.$('releaseInfo.viewGallery', {
+                link:
+                  relations.galleryLink
+                    .slot('content', language.$('releaseInfo.viewGallery.link')),
               }),
-          },
-        ],
 
-        navContent:
-          relations.chronologyLinks,
-
-        banner: relations.banner ?? null,
-        bannerPosition: 'top',
-
-        secondaryNav: relations.secondaryNav,
-
-        leftSidebar: relations.sidebar,
-
-        socialEmbed: relations.socialEmbed,
-      });
-  },
+            !relations.galleryLink && relations.commentaryLink &&
+              language.$('releaseInfo.viewCommentary', {
+                link:
+                  relations.commentaryLink
+                    .slot('content', language.$('releaseInfo.viewCommentary.link')),
+              }),
+          ]),
+
+        relations.trackList,
+
+        html.tag('p',
+          {[html.onlyIfContent]: true},
+          {[html.joinChildren]: html.tag('br')},
+
+          [
+            language.$('releaseInfo.addedToWiki', {
+              [language.onlyIfOptions]: ['date'],
+              date: language.formatDate(data.dateAddedToWiki),
+            }),
+          ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'additional-files'},
+              title: language.$('releaseInfo.additionalFiles.heading'),
+            }),
+
+          relations.additionalFilesList,
+        ]),
+
+        relations.artistCommentarySection,
+      ],
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {
+          auto: 'current',
+          accent:
+            relations.albumNavAccent.slots({
+              showTrackNavigation: true,
+              showExtraLinks: true,
+            }),
+        },
+      ],
+
+      navContent:
+        relations.chronologyLinks,
+
+      banner: relations.banner ?? null,
+      bannerPosition: 'top',
+
+      secondaryNav: relations.secondaryNav,
+
+      leftSidebar: relations.sidebar,
+
+      socialEmbed: relations.socialEmbed,
+    }),
 };