« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackFeaturedInFlashesList.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateTrackFeaturedInFlashesList.js')
-rw-r--r--src/content/dependencies/generateTrackFeaturedInFlashesList.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTrackFeaturedInFlashesList.js b/src/content/dependencies/generateTrackFeaturedInFlashesList.js
new file mode 100644
index 00000000..f13368d1
--- /dev/null
+++ b/src/content/dependencies/generateTrackFeaturedInFlashesList.js
@@ -0,0 +1,38 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  relations: (relation, features, track) => ({
+    flashLinks:
+      features
+        .map(({flash}) => relation('linkFlash', flash)),
+
+    trackLinks:
+      features
+        .map(({as: directlyFeaturedTrack}) =>
+          (directlyFeaturedTrack === track
+            ? null
+         : directlyFeaturedTrack.name === track.name
+            ? null
+            : relation('linkTrack', directlyFeaturedTrack))),
+  }),
+
+  generate: (relations, {html, language}) =>
+    html.tag('ul',
+      {[html.onlyIfContent]: true},
+
+      stitchArrays({
+        flashLink: relations.flashLinks,
+        trackLink: relations.trackLinks,
+      }).map(({flashLink, trackLink}) => {
+          const attributes = html.attributes();
+          const parts = ['flashList.item'];
+          const options = {flash: flashLink};
+
+          if (trackLink) {
+            parts.push('asDifferentRelease');
+            options.track = trackLink;
+          }
+
+          return html.tag('li', attributes, language.$(...parts, options));
+        })),
+};