« 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/generateTrackInfoPage.js585
1 files changed, 278 insertions, 307 deletions
diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js
index 04e9f274..bffebe07 100644
--- a/src/content/dependencies/generateTrackInfoPage.js
+++ b/src/content/dependencies/generateTrackInfoPage.js
@@ -1,5 +1,3 @@
-import {empty} from '#sugar';
-
 export default {
   contentDependencies: [
     'generateAlbumAdditionalFilesList',
@@ -32,382 +30,355 @@ export default {
       wikiInfo.divideTrackListsByGroups,
   }),
 
-  relations(relation, sprawl, track) {
-    const relations = {};
-    const sections = relations.sections = {};
-    const {album} = track;
-
-    relations.layout =
-      relation('generatePageLayout');
-
-    relations.albumStyleRules =
-      relation('generateAlbumStyleRules', track.album, track);
-
-    relations.socialEmbed =
-      relation('generateTrackSocialEmbed', track);
+  relations: (relation, sprawl, track) => ({
+    layout:
+      relation('generatePageLayout'),
 
-    relations.albumLink =
-      relation('linkAlbum', track.album);
+    albumStyleRules:
+      relation('generateAlbumStyleRules', track.album, track),
 
-    relations.trackLink =
-      relation('linkTrack', track);
+    socialEmbed:
+      relation('generateTrackSocialEmbed', track),
 
-    relations.albumNavAccent =
-      relation('generateAlbumNavAccent', track.album, track);
+    albumLink:
+      relation('linkAlbum', track.album),
 
-    relations.trackChronologyLinks =
-      relation('generateTrackChronologyLinks', track);
+    trackLink:
+      relation('linkTrack', track),
 
-    relations.secondaryNav =
-      relation('generateAlbumSecondaryNav', track.album);
+    albumNavAccent:
+      relation('generateAlbumNavAccent', track.album, track),
 
-    relations.sidebar =
-      relation('generateAlbumSidebar', track.album, track);
+    trackChronologyLinks:
+      relation('generateTrackChronologyLinks', track),
 
-    // This'll take care of itself being blank if there's nothing to show here.
-    relations.additionalNamesBox =
-      relation('generateTrackAdditionalNamesBox', track);
+    secondaryNav:
+      relation('generateAlbumSecondaryNav', track.album),
 
-    if (track.hasUniqueCoverArt || album.hasCoverArt) {
-      relations.cover =
-        relation('generateTrackCoverArtwork', track);
-    }
+    sidebar:
+      relation('generateAlbumSidebar', track.album, track),
 
-    relations.contentHeading =
-      relation('generateContentHeading');
+    additionalNamesBox:
+      relation('generateTrackAdditionalNamesBox', track),
 
-    // Section: Release info
+    cover:
+      (track.hasUniqueCoverArt || track.album.hasCoverArt
+        ? relation('generateTrackCoverArtwork', track)
+        : null),
 
-    relations.releaseInfo =
-      relation('generateTrackReleaseInfo', track);
+    contentHeading:
+      relation('generateContentHeading'),
 
-    // Section: Other releases
+    releaseInfo:
+      relation('generateTrackReleaseInfo', track),
 
-    relations.otherReleasesList =
-        relation('generateTrackInfoPageOtherReleasesList', track);
+    otherReleasesList:
+        relation('generateTrackInfoPageOtherReleasesList', track),
 
-    // Section: Contributors
+    contributorContributionList:
+      relation('generateContributionList', track.contributorContribs),
 
-    relations.contributorContributionList =
-      relation('generateContributionList', track.contributorContribs);
+    referencedTracksList:
+      relation('generateTrackList', track.referencedTracks),
 
-    relations.referencedTracksList =
-      relation('generateTrackList', track.referencedTracks);
+    sampledTracksList:
+      relation('generateTrackList', track.sampledTracks),
 
-    // Section: Sampled tracks
-
-    relations.sampledTracksList =
-      relation('generateTrackList', track.sampledTracks);
-
-    // Section: Tracks that reference
-
-    relations.referencedByTracksList =
+    referencedByTracksList:
       relation('generateTrackListDividedByGroups',
         track.referencedByTracks,
-        sprawl.divideTrackListsByGroups);
-
-    // Section: Tracks that sample
+        sprawl.divideTrackListsByGroups),
 
-    relations.sampledByTracksList =
+    sampledByTracksList:
       relation('generateTrackListDividedByGroups',
         track.sampledByTracks,
-        sprawl.divideTrackListsByGroups);
+        sprawl.divideTrackListsByGroups),
 
-    // Section: Flashes that feature
+    flashesThatFeatureList:
+      relation('generateTrackInfoPageFeaturedByFlashesList', track),
 
-    relations.flashesThatFeatureList =
-      relation('generateTrackInfoPageFeaturedByFlashesList', track);
+    lyrics:
+      relation('transformContent', track.lyrics),
 
-    // Section: Lyrics
-
-    relations.lyrics =
-      relation('transformContent', track.lyrics);
-
-    // Sections: Sheet music files, MIDI/proejct files, additional files
-
-    relations.sheetMusicFilesList =
+    sheetMusicFilesList:
       relation('generateAlbumAdditionalFilesList',
-        album,
-        track.sheetMusicFiles);
+        track.album,
+        track.sheetMusicFiles),
 
-    relations.midiProjectFilesList =
+    midiProjectFilesList:
       relation('generateAlbumAdditionalFilesList',
-        album,
-        track.midiProjectFiles);
+        track.album,
+        track.midiProjectFiles),
 
-    relations.additionalFilesList =
+    additionalFilesList:
       relation('generateAlbumAdditionalFilesList',
-        album,
-        track.additionalFiles);
-
-    // Section: Artist commentary
-
-    relations.artistCommentarySection =
-      relation('generateCommentarySection', track.commentary);
-
-    return relations;
-  },
-
-  data(sprawl, track) {
-    return {
-      name: track.name,
-      color: track.color,
+        track.album,
+        track.additionalFiles),
 
-      hasTrackNumbers: track.album.hasTrackNumbers,
-      trackNumber: track.album.tracks.indexOf(track) + 1,
-    };
-  },
+    artistCommentarySection:
+      relation('generateCommentarySection', track.commentary),
+  }),
 
-  generate(data, relations, {html, language}) {
-    const {sections: sec} = relations;
+  data: (sprawl, track) => ({
+    name:
+      track.name,
 
-    return relations.layout
-      .slots({
-        title: language.$('trackPage.title', {track: data.name}),
-        headingMode: 'sticky',
+    color:
+      track.color,
 
-        additionalNames: relations.additionalNamesBox,
+    hasTrackNumbers:
+      track.album.hasTrackNumbers,
 
-        color: data.color,
-        styleRules: [relations.albumStyleRules],
+    trackNumber:
+      track.album.tracks.indexOf(track) + 1,
+  }),
 
-        cover:
-          (relations.cover
-            ? relations.cover.slots({
-                alt: language.$('misc.alt.trackCover'),
-              })
-            : null),
+  generate: (data, relations, {html, language}) =>
+    relations.layout.slots({
+      title: language.$('trackPage.title', {track: data.name}),
+      headingMode: 'sticky',
 
-        mainContent: [
-          relations.releaseInfo,
+      additionalNames: relations.additionalNamesBox,
 
-          html.tag('p',
-            {[html.onlyIfContent]: true},
-            {[html.joinChildren]: html.tag('br')},
-
-            [
-              !html.isBlank(relations.sheetMusicFilesList) &&
-                language.$('releaseInfo.sheetMusicFiles.shortcut', {
-                  link: html.tag('a',
-                    {href: '#sheet-music-files'},
-                    language.$('releaseInfo.sheetMusicFiles.shortcut.link')),
-                }),
+      color: data.color,
+      styleRules: [relations.albumStyleRules],
 
-              !html.isBlank(relations.midiProjectFilesList) &&
-                language.$('releaseInfo.midiProjectFiles.shortcut', {
-                  link: html.tag('a',
-                    {href: '#midi-project-files'},
-                    language.$('releaseInfo.midiProjectFiles.shortcut.link')),
-                }),
+      cover:
+        (relations.cover
+          ? relations.cover.slots({
+              alt: language.$('misc.alt.trackCover'),
+            })
+          : null),
 
-              !html.isBlank(relations.additionalFilesList) &&
-                language.$('releaseInfo.additionalFiles.shortcut', {
-                  link: html.tag('a',
-                    {href: '#midi-project-files'},
-                    language.$('releaseInfo.additionalFiles.shortcut.link')),
-                }),
+      mainContent: [
+        relations.releaseInfo,
 
-              !html.isBlank(relations.artistCommentarySection) &&
-                language.$('releaseInfo.readCommentary', {
-                  link: html.tag('a',
-                    {href: '#artist-commentary'},
-                    language.$('releaseInfo.readCommentary.link')),
-                }),
-            ]),
+        html.tag('p',
+          {[html.onlyIfContent]: true},
+          {[html.joinChildren]: html.tag('br')},
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'also-released-as'},
-                title: language.$('releaseInfo.alsoReleasedAs'),
+          [
+            !html.isBlank(relations.sheetMusicFilesList) &&
+              language.$('releaseInfo.sheetMusicFiles.shortcut', {
+                link: html.tag('a',
+                  {href: '#sheet-music-files'},
+                  language.$('releaseInfo.sheetMusicFiles.shortcut.link')),
               }),
 
-            relations.otherReleasesList,
-          ]),
-
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'contributors'},
-                title: language.$('releaseInfo.contributors'),
+            !html.isBlank(relations.midiProjectFilesList) &&
+              language.$('releaseInfo.midiProjectFiles.shortcut', {
+                link: html.tag('a',
+                  {href: '#midi-project-files'},
+                  language.$('releaseInfo.midiProjectFiles.shortcut.link')),
               }),
 
-            relations.contributorContributionList,
-          ]),
-
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'references'},
-
-                title:
-                  language.$('releaseInfo.tracksReferenced', {
-                    track: html.tag('i', data.name),
-                  }),
-
-                stickyTitle:
-                  language.$('releaseInfo.tracksReferenced.sticky'),
+            !html.isBlank(relations.additionalFilesList) &&
+              language.$('releaseInfo.additionalFiles.shortcut', {
+                link: html.tag('a',
+                  {href: '#midi-project-files'},
+                  language.$('releaseInfo.additionalFiles.shortcut.link')),
               }),
 
-            relations.referencedTracksList,
-          ]),
-
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'samples'},
-
-                title:
-                  language.$('releaseInfo.tracksSampled', {
-                    track: html.tag('i', data.name),
-                  }),
-
-                stickyTitle:
-                  language.$('releaseInfo.tracksSampled.sticky'),
+            !html.isBlank(relations.artistCommentarySection) &&
+              language.$('releaseInfo.readCommentary', {
+                link: html.tag('a',
+                  {href: '#artist-commentary'},
+                  language.$('releaseInfo.readCommentary.link')),
               }),
-
-            relations.sampledTracksList,
           ]),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'referenced-by'},
-
-                title:
-                  language.$('releaseInfo.tracksThatReference', {
-                    track: html.tag('i', data.name),
-                  }),
-
-                stickyTitle:
-                  language.$('releaseInfo.tracksThatReference.sticky'),
-              }),
-
-            relations.referencedByTracksList
-              .slots({
-                headingString: 'releaseInfo.tracksThatReference',
-              }),
-          ]),
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'also-released-as'},
+              title: language.$('releaseInfo.alsoReleasedAs'),
+            }),
+
+          relations.otherReleasesList,
+        ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'contributors'},
+              title: language.$('releaseInfo.contributors'),
+            }),
+
+          relations.contributorContributionList,
+        ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'references'},
+
+              title:
+                language.$('releaseInfo.tracksReferenced', {
+                  track: html.tag('i', data.name),
+                }),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'sampled-by'},
+              stickyTitle:
+                language.$('releaseInfo.tracksReferenced.sticky'),
+            }),
 
-                title:
-                  language.$('releaseInfo.tracksThatSample', {
-                    track: html.tag('i', data.name),
-                  }),
+          relations.referencedTracksList,
+        ]),
 
-                stickyTitle:
-                  language.$('releaseInfo.tracksThatSample.sticky'),
-              }),
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'samples'},
 
-            relations.sampledByTracksList
-              .slots({
-                headingString: 'releaseInfo.tracksThatSample',
-              }),
-          ]),
+              title:
+                language.$('releaseInfo.tracksSampled', {
+                  track: html.tag('i', data.name),
+                }),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'featured-in'},
+              stickyTitle:
+                language.$('releaseInfo.tracksSampled.sticky'),
+            }),
 
-                title:
-                  language.$('releaseInfo.flashesThatFeature', {
-                    track: html.tag('i', data.name),
-                  }),
+          relations.sampledTracksList,
+        ]),
 
-                stickyTitle:
-                  language.$('releaseInfo.flashesThatFeature.sticky'),
-              }),
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'referenced-by'},
 
-            relations.flashesThatFeatureList,
-          ]),
+              title:
+                language.$('releaseInfo.tracksThatReference', {
+                  track: html.tag('i', data.name),
+                }),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'lyrics'},
-                title: language.$('releaseInfo.lyrics'),
-              }),
+              stickyTitle:
+                language.$('releaseInfo.tracksThatReference.sticky'),
+            }),
 
-            html.tag('blockquote',
-              {[html.onlyIfContent]: true},
-              relations.lyrics.slot('mode', 'lyrics')),
-          ]),
+          relations.referencedByTracksList
+            .slots({
+              headingString: 'releaseInfo.tracksThatReference',
+            }),
+        ]),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'sheet-music-files'},
-                title: language.$('releaseInfo.sheetMusicFiles.heading'),
-              }),
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'sampled-by'},
 
-            relations.sheetMusicFilesList,
-          ]),
+              title:
+                language.$('releaseInfo.tracksThatSample', {
+                  track: html.tag('i', data.name),
+                }),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'midi-project-files'},
-                title: language.$('releaseInfo.midiProjectFiles.heading'),
-              }),
+              stickyTitle:
+                language.$('releaseInfo.tracksThatSample.sticky'),
+            }),
 
-            relations.midiProjectFilesList,
-          ]),
+          relations.sampledByTracksList
+            .slots({
+              headingString: 'releaseInfo.tracksThatSample',
+            }),
+        ]),
 
-          html.tags([
-            relations.contentHeading.clone()
-              .slots({
-                attributes: {id: 'additional-files'},
-                title: language.$('releaseInfo.additionalFiles.heading'),
-              }),
-
-            relations.additionalFilesList,
-          ]),
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'featured-in'},
 
-          relations.artistCommentarySection,
-        ],
-
-        navLinkStyle: 'hierarchical',
-        navLinks: [
-          {auto: 'home'},
-          {html: relations.albumLink.slot('color', false)},
-          {
-            html:
-              (data.hasTrackNumbers
-                ? language.$('trackPage.nav.track.withNumber', {
-                    number: data.trackNumber,
-                    track: relations.trackLink
-                      .slot('attributes', {class: 'current'}),
-                  })
-                : language.$('trackPage.nav.track', {
-                    track: relations.trackLink
-                      .slot('attributes', {class: 'current'}),
-                  })),
-          },
-        ],
-
-        navBottomRowContent:
-          relations.albumNavAccent.slots({
-            showTrackNavigation: true,
-            showExtraLinks: false,
-          }),
+              title:
+                language.$('releaseInfo.flashesThatFeature', {
+                  track: html.tag('i', data.name),
+                }),
 
-        navContent:
-          relations.trackChronologyLinks,
+              stickyTitle:
+                language.$('releaseInfo.flashesThatFeature.sticky'),
+            }),
 
-        secondaryNav:
-          relations.secondaryNav
-            .slot('mode', 'track'),
+          relations.flashesThatFeatureList,
+        ]),
 
-        leftSidebar: relations.sidebar,
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'lyrics'},
+              title: language.$('releaseInfo.lyrics'),
+            }),
 
-        socialEmbed: relations.socialEmbed,
-      });
-  },
+          html.tag('blockquote',
+            {[html.onlyIfContent]: true},
+            relations.lyrics.slot('mode', 'lyrics')),
+        ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'sheet-music-files'},
+              title: language.$('releaseInfo.sheetMusicFiles.heading'),
+            }),
+
+          relations.sheetMusicFilesList,
+        ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'midi-project-files'},
+              title: language.$('releaseInfo.midiProjectFiles.heading'),
+            }),
+
+          relations.midiProjectFilesList,
+        ]),
+
+        html.tags([
+          relations.contentHeading.clone()
+            .slots({
+              attributes: {id: 'additional-files'},
+              title: language.$('releaseInfo.additionalFiles.heading'),
+            }),
+
+          relations.additionalFilesList,
+        ]),
+
+        relations.artistCommentarySection,
+      ],
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {html: relations.albumLink.slot('color', false)},
+        {
+          html:
+            (data.hasTrackNumbers
+              ? language.$('trackPage.nav.track.withNumber', {
+                  number: data.trackNumber,
+                  track: relations.trackLink
+                    .slot('attributes', {class: 'current'}),
+                })
+              : language.$('trackPage.nav.track', {
+                  track: relations.trackLink
+                    .slot('attributes', {class: 'current'}),
+                })),
+        },
+      ],
+
+      navBottomRowContent:
+        relations.albumNavAccent.slots({
+          showTrackNavigation: true,
+          showExtraLinks: false,
+        }),
+
+      navContent:
+        relations.trackChronologyLinks,
+
+      secondaryNav:
+        relations.secondaryNav
+          .slot('mode', 'track'),
+
+      leftSidebar: relations.sidebar,
+
+      socialEmbed: relations.socialEmbed,
+    }),
 };
 
 /*