« get me outta code hell

content: generateTrackReferencedArtworksPage - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackReferencedArtworksPage.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-17 16:38:07 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 16:39:59 -0400
commit257b7616e3a0997f2a5c2766c7923719cf2ca0b5 (patch)
tree366ad2dfca2643c1a0a59b238b98cad0abce0e8f /src/content/dependencies/generateTrackReferencedArtworksPage.js
parent9c3da1ff14bf2760a6358bcab1bdc97f012c2b46 (diff)
content: generateTrackReferencedArtworksPage
Diffstat (limited to 'src/content/dependencies/generateTrackReferencedArtworksPage.js')
-rw-r--r--src/content/dependencies/generateTrackReferencedArtworksPage.js143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTrackReferencedArtworksPage.js b/src/content/dependencies/generateTrackReferencedArtworksPage.js
new file mode 100644
index 00000000..545276c5
--- /dev/null
+++ b/src/content/dependencies/generateTrackReferencedArtworksPage.js
@@ -0,0 +1,143 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateAlbumStyleRules',
+    'generateBackToTrackLink',
+    'generateCoverGrid',
+    'generatePageLayout',
+    'generateTrackCoverArtwork',
+    'generateTrackNavLinks',
+    'image',
+    'linkAlbum',
+    'linkTrack',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, track) => ({
+    layout:
+      relation('generatePageLayout'),
+
+    albumStyleRules:
+      relation('generateAlbumStyleRules', track.album, track),
+
+    navLinks:
+      relation('generateTrackNavLinks', track),
+
+    backToTrackLink:
+      relation('generateBackToTrackLink', track),
+
+    cover:
+      relation('generateTrackCoverArtwork', track),
+
+    coverGrid:
+      relation('generateCoverGrid'),
+
+    links:
+      track.referencedArtworks
+        .map(({thing}) =>
+          (thing.album
+            ? relation('linkTrack', thing)
+            : relation('linkAlbum', thing))),
+
+    images:
+      track.referencedArtworks
+        .map(({thing}) =>
+          relation('image', thing.artTags)),
+  }),
+
+  data: (track) => ({
+    name:
+      track.name,
+
+    color:
+      track.color,
+
+    count:
+      track.referencedArtworks.length,
+
+    names:
+      track.referencedArtworks
+        .map(({thing}) => thing.name),
+
+    paths:
+      track.referencedArtworks
+        .map(({thing}) =>
+          (thing.album
+            ? ['media.trackCover', thing.album.directory, thing.directory, thing.coverArtFileExtension]
+            : ['media.albumCover', thing.directory, thing.coverArtFileExtension])),
+
+    dimensions:
+      track.referencedArtworks
+        .map(({thing}) => thing.coverArtDimensions),
+
+    coverArtistNames:
+      track.referencedArtworks
+        .map(({thing}) =>
+          thing.coverArtistContribs
+            .map(contrib => contrib.artist.name)),
+  }),
+
+  generate: (data, relations, {html, language}) =>
+    language.encapsulate('trackReferencedArtworksPage', pageCapsule =>
+      relations.layout.slots({
+        title:
+          language.$(pageCapsule, 'title', {
+            track:
+              data.name,
+          }),
+
+        subtitle:
+          language.$(pageCapsule, 'subtitle'),
+
+        color: data.color,
+        styleRules: [relations.albumStyleRules],
+
+        cover:
+          relations.cover
+            .slot('mode', 'primary-artists'),
+
+        mainClasses: ['top-index'],
+        mainContent: [
+          html.tag('p', {class: 'quick-info'},
+            language.$(pageCapsule, 'statsLine', {
+              artworks:
+                language.countArtworks(data.count, {
+                  unit: true,
+                }),
+            })),
+
+          relations.coverGrid.slots({
+            links: relations.links,
+            names: data.names,
+
+            images:
+              stitchArrays({
+                image: relations.images,
+                path: data.paths,
+                dimensions: data.dimensions,
+              }).map(({image, path, dimensions}) =>
+                  image.slots({
+                    path,
+                    dimensions,
+                  })),
+
+            info:
+              data.coverArtistNames.map(names =>
+                language.$('misc.coverGrid.details.coverArtists', {
+                  artists:
+                    language.formatUnitList(names),
+                })),
+          }),
+        ],
+
+        navLinkStyle: 'hierarchical',
+        navLinks:
+          html.resolve(
+            relations.navLinks
+              .slot('currentExtra', 'referenced-art')),
+
+        navBottomRowContent: relations.backToTrackLink,
+      })),
+};