« get me outta code hell

content: generateTrackNavLinks - 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>2024-11-17 16:37:43 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 16:37:43 -0400
commit9c3da1ff14bf2760a6358bcab1bdc97f012c2b46 (patch)
tree6d4d3bb22c6d62abeeffb1fed834972a33f86df2 /src/content/dependencies
parent4f92f6e3b7fedaf735a73404e5728ca0965ad9ac (diff)
content: generateTrackNavLinks
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateTrackInfoPage.js39
-rw-r--r--src/content/dependencies/generateTrackNavLinks.js47
2 files changed, 51 insertions, 35 deletions
diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js
index c3faef20..160acc32 100644
--- a/src/content/dependencies/generateTrackInfoPage.js
+++ b/src/content/dependencies/generateTrackInfoPage.js
@@ -15,6 +15,7 @@ export default {
     'generateTrackInfoPageOtherReleasesList',
     'generateTrackList',
     'generateTrackListDividedByGroups',
+    'generateTrackNavLinks',
     'generateTrackReleaseInfo',
     'generateTrackSocialEmbed',
     'linkAlbum',
@@ -39,11 +40,8 @@ export default {
     socialEmbed:
       relation('generateTrackSocialEmbed', track),
 
-    albumLink:
-      relation('linkAlbum', track.album),
-
-    trackLink:
-      relation('linkTrack', track),
+    navLinks:
+      relation('generateTrackNavLinks', track),
 
     albumNavAccent:
       relation('generateAlbumNavAccent', track.album, track),
@@ -124,12 +122,6 @@ export default {
 
     color:
       track.color,
-
-    hasTrackNumbers:
-      track.album.hasTrackNumbers,
-
-    trackNumber:
-      track.album.tracks.indexOf(track) + 1,
   }),
 
   generate: (data, relations, {html, language}) =>
@@ -379,30 +371,7 @@ export default {
         ],
 
         navLinkStyle: 'hierarchical',
-
-        navLinks: [
-          {auto: 'home'},
-
-          {html: relations.albumLink.slot('color', false)},
-
-          {
-            html:
-              language.encapsulate(pageCapsule, 'nav.track', workingCapsule => {
-                const workingOptions = {};
-
-                workingOptions.track =
-                  relations.trackLink
-                    .slot('attributes', {class: 'current'});
-
-                if (data.hasTrackNumbers) {
-                  workingCapsule += '.withNumber';
-                  workingOptions.number = data.trackNumber;
-                }
-
-                return language.$(workingCapsule, workingOptions);
-              }),
-          },
-        ],
+        navLinks: html.resolve(relations.navLinks),
 
         navBottomRowContent:
           relations.albumNavAccent.slots({
diff --git a/src/content/dependencies/generateTrackNavLinks.js b/src/content/dependencies/generateTrackNavLinks.js
new file mode 100644
index 00000000..89da171a
--- /dev/null
+++ b/src/content/dependencies/generateTrackNavLinks.js
@@ -0,0 +1,47 @@
+export default {
+  contentDependencies: ['linkAlbum', 'linkTrack'],
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, track) => ({
+    albumLink:
+      relation('linkAlbum', track.album),
+
+    trackLink:
+      relation('linkTrack', track),
+  }),
+
+  data: (track) => ({
+    hasTrackNumbers:
+      track.album.hasTrackNumbers,
+
+    trackNumber:
+      track.album.tracks.indexOf(track) + 1,
+  }),
+
+  slots: {},
+
+  generate: (data, relations, slots, {html, language}) =>
+    language.encapsulate('trackPage.nav', navCapsule => [
+      {auto: 'home'},
+
+      {html: relations.albumLink.slot('color', false)},
+
+      {
+        html:
+          language.encapsulate(navCapsule, 'track', workingCapsule => {
+            const workingOptions = {};
+
+            workingOptions.track =
+              relations.trackLink
+                .slot('attributes', {class: 'current'});
+
+            if (data.hasTrackNumbers) {
+              workingCapsule += '.withNumber';
+              workingOptions.number = data.trackNumber;
+            }
+
+            return language.$(workingCapsule, workingOptions);
+          }),
+      },
+    ]),
+};