« get me outta code hell

content: generate{Album,}ReferencedArtworksPage - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateReferencedArtworksPage.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-17 18:16:18 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 18:16:18 -0400
commitec129ac9ce0b143ca4c325108ea66c2d0e7352ff (patch)
tree0dad7fa2757aa91ed698443d8767722071caed4f /src/content/dependencies/generateReferencedArtworksPage.js
parent6acbc628cb111c53d0b312ab90cd4807ad4bd8d1 (diff)
content: generate{Album,}ReferencedArtworksPage
Diffstat (limited to 'src/content/dependencies/generateReferencedArtworksPage.js')
-rw-r--r--src/content/dependencies/generateReferencedArtworksPage.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/content/dependencies/generateReferencedArtworksPage.js b/src/content/dependencies/generateReferencedArtworksPage.js
new file mode 100644
index 00000000..fa65a245
--- /dev/null
+++ b/src/content/dependencies/generateReferencedArtworksPage.js
@@ -0,0 +1,121 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateCoverGrid',
+    'generatePageLayout',
+    'image',
+    'linkAlbum',
+    'linkTrack',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, referencedArtworks) => ({
+    layout:
+      relation('generatePageLayout'),
+
+    coverGrid:
+      relation('generateCoverGrid'),
+
+    links:
+      referencedArtworks.map(({thing}) =>
+        (thing.album
+          ? relation('linkTrack', thing)
+          : relation('linkAlbum', thing))),
+
+    images:
+      referencedArtworks.map(({thing}) =>
+        relation('image', thing.artTags)),
+  }),
+
+  data: (referencedArtworks) => ({
+    count:
+      referencedArtworks.length,
+
+    names:
+      referencedArtworks
+        .map(({thing}) => thing.name),
+
+    paths:
+      referencedArtworks
+        .map(({thing}) =>
+          (thing.album
+            ? ['media.trackCover', thing.album.directory, thing.directory, thing.coverArtFileExtension]
+            : ['media.albumCover', thing.directory, thing.coverArtFileExtension])),
+
+    dimensions:
+      referencedArtworks
+        .map(({thing}) => thing.coverArtDimensions),
+
+    coverArtistNames:
+      referencedArtworks
+        .map(({thing}) =>
+          thing.coverArtistContribs
+            .map(contrib => contrib.artist.name)),
+  }),
+
+  slots: {
+    color: {validate: v => v.isColor},
+
+    styleRules: {type: 'html', mutable: false},
+
+    title: {type: 'html', mutable: false},
+    cover: {type: 'html', mutable: true},
+
+    navLinks: {validate: v => v.isArray},
+    navBottomRowContent: {type: 'html', mutable: false},
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    language.encapsulate('referencedArtworksPage', pageCapsule =>
+      relations.layout.slots({
+        title: slots.title,
+        subtitle: language.$(pageCapsule, 'subtitle'),
+
+        color: slots.color,
+        styleRules: slots.styleRules,
+
+        cover:
+          slots.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: slots.navLinks,
+        navBottomRowContent: slots.navBottomRowContent,
+      })),
+};