« get me outta code hell

content: generateTrackInfoPageContent: flashes that feature section - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-26 09:57:37 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-26 09:57:37 -0300
commit030bd24e02bbc7c7c63833c652835838e2f9c471 (patch)
treecb7cca3eca00daa55912212d2c1581c127c9f921 /src/content/dependencies
parent8c522ef371cf01d0749f03d884bea17f360d7161 (diff)
content: generateTrackInfoPageContent: flashes that feature section
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateTrackInfoPageContent.js111
1 files changed, 69 insertions, 42 deletions
diff --git a/src/content/dependencies/generateTrackInfoPageContent.js b/src/content/dependencies/generateTrackInfoPageContent.js
index a67c37c0..9f3dc8e7 100644
--- a/src/content/dependencies/generateTrackInfoPageContent.js
+++ b/src/content/dependencies/generateTrackInfoPageContent.js
@@ -1,4 +1,5 @@
 import {empty} from '../../util/sugar.js';
+import {sortChronologically} from '../../util/wiki-data.js';
 
 export default {
   contentDependencies: [
@@ -14,9 +15,15 @@ export default {
     'linkTrack',
   ],
 
-  extraDependencies: ['html', 'language'],
+  extraDependencies: ['html', 'language', 'wikiData'],
 
-  relations(relation, track, {topLevelGroups}) {
+  sprawl({wikiInfo}) {
+    return {
+      enableFlashesAndGames: wikiInfo.enableFlashesAndGames,
+    };
+  },
+
+  relations(relation, sprawl, track, {topLevelGroups}) {
     const {album} = track;
 
     const relations = {};
@@ -122,6 +129,42 @@ export default {
           topLevelGroups);
     }
 
+    // Section: Flashes that feature
+
+    if (sprawl.enableFlashesAndGames) {
+      const sortedFeatures =
+        sortChronologically(
+          [track, ...track.otherReleases].flatMap(track =>
+            track.featuredInFlashes.map(flash => ({
+              // These aren't going to be exposed directly, they're processed
+              // into the appropriate relations after this sort.
+              flash, track,
+
+              // These properties are only used for the sort.
+              date: flash.date,
+              name: flash.name,
+              directory: flash.directory,
+            }))));
+
+      if (!empty(sortedFeatures)) {
+        const flashesThatFeature = sections.flashesThatFeature = {};
+
+        flashesThatFeature.heading =
+          relation('generateContentHeading');
+
+        flashesThatFeature.entries =
+          sortedFeatures.map(({flash, track: directlyFeaturedTrack}) =>
+            (directlyFeaturedTrack === track
+              ? {
+                  flashLink: relation('linkFlash', flash),
+                }
+              : {
+                  flashLink: relation('linkFlash', flash),
+                  trackLink: relation('linkTrack', directlyFeaturedTrack),
+                }));
+      }
+    }
+
     // Section: Lyrics
 
     if (track.lyrics) {
@@ -163,7 +206,7 @@ export default {
     return relations;
   },
 
-  data(track) {
+  data(sprawl, track) {
     const data = {};
 
     const {album} = track;
@@ -358,6 +401,29 @@ export default {
           sec.referencedBy.list,
         ],
 
+        sec.flashesThatFeature && [
+          sec.flashesThatFeature.heading
+            .slots({
+              id: 'featured-in',
+              title:
+                language.$('releaseInfo.flashesThatFeature', {
+                  track: html.tag('i', data.name),
+                }),
+            }),
+
+          html.tag('ul', sec.flashesThatFeature.entries.map(({flashLink, trackLink}) =>
+            (trackLink
+              ? html.tag('li', {class: 'rerelease'},
+                  language.$('releaseInfo.flashesThatFeature.item.asDifferentRelease', {
+                    flash: flashLink,
+                    track: trackLink,
+                  }))
+              : html.tag('li',
+                  language.$('releaseInfo.flashesThatFeature.item', {
+                    flash: flashLink,
+                  }))))),
+        ],
+
         sec.lyrics && [
           sec.lyrics.heading
             .slots({
@@ -430,21 +496,6 @@ export function write(track, {wikiData}) {
 
   const listTag = getAlbumListTag(album);
 
-  let flashesThatFeature;
-  if (wikiInfo.enableFlashesAndGames) {
-    flashesThatFeature = sortChronologically(
-      [track, ...otherReleases].flatMap((track) =>
-        track.featuredInFlashes.map((flash) => ({
-          flash,
-          as: track,
-          directory: flash.directory,
-          name: flash.name,
-          date: flash.date,
-        }))
-      )
-    );
-  }
-
   const unbound_getTrackItem = (track, {
     getArtistString,
     html,
@@ -703,30 +754,6 @@ export function write(track, {wikiData}) {
               ]),
 
             ...html.fragment(
-              wikiInfo.enableFlashesAndGames &&
-              !empty(flashesThatFeature) && [
-                generateContentHeading({
-                  id: 'featured-in',
-                  title:
-                    language.$('releaseInfo.flashesThatFeature', {
-                      track: html.tag('i', track.name),
-                    }),
-                }),
-
-                html.tag('ul', flashesThatFeature.map(({flash, as}) =>
-                  html.tag('li',
-                    {class: as !== track && 'rerelease'},
-                    (as === track
-                      ? language.$('releaseInfo.flashesThatFeature.item', {
-                        flash: link.flash(flash),
-                      })
-                      : language.$('releaseInfo.flashesThatFeature.item.asDifferentRelease', {
-                        flash: link.flash(flash),
-                        track: link.track(as),
-                      }))))),
-              ]),
-
-            ...html.fragment(
               track.lyrics && [
                 generateContentHeading({
                   id: 'lyrics',