« get me outta code hell

content, data: Track.previousProductionTracks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-10-23 19:23:18 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-10-23 19:23:18 -0300
commit6b9c8cb3615b7ba7b49d1c21b2748d2e75e7ee82 (patch)
tree495d659cd1bbba542b21f364223c4e211ccbb68c /src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js
parent2d8622f8b31df0367ded52a45d7362abfe6d9a7c (diff)
content, data: Track.previousProductionTracks
Diffstat (limited to 'src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js')
-rw-r--r--src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js b/src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js
new file mode 100644
index 00000000..b2f50cf3
--- /dev/null
+++ b/src/content/dependencies/generateTrackInfoPagePreviousProductionLine.js
@@ -0,0 +1,37 @@
+import {stitchArrays} from '#sugar';
+import {getKebabCase} from '#wiki-data';
+
+export default {
+  relations: (relation, track) => ({
+    trackLinks:
+      track.followingProductionTracks
+        .map(track => relation('linkTrack', track)),
+
+    albumLinks:
+      track.followingProductionTracks
+        .map(following =>
+          (following.album !== track.album &&
+           getKebabCase(following.name) === getKebabCase(track.name)
+
+            ? relation('linkAlbum', following.album)
+            : null)),
+  }),
+
+  generate: (relations, {language}) =>
+    language.encapsulate('releaseInfo.previousProduction', capsule =>
+      language.$(capsule, {
+        [language.onlyIfOptions]: ['tracks'],
+
+        tracks:
+          stitchArrays({
+            trackLink: relations.trackLinks,
+            albumLink: relations.albumLinks,
+          }).map(({trackLink, albumLink}) =>
+              (albumLink
+                ? language.$(capsule, 'trackOnAlbum', {
+                    track: trackLink,
+                    album: albumLink,
+                  })
+                : trackLink)),
+      })),
+};