« get me outta code hell

content: generateArtTagGalleryPage - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-15 19:56:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-15 19:56:44 -0300
commitf238efbf84d262274c28c04c0881a5464caf6a03 (patch)
tree6a731d6f2cbe9841c547e44b76a385d11fee8815 /src/content
parent537448501439aaa68485e2ac436941656d7250e8 (diff)
content: generateArtTagGalleryPage
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateArtTagGalleryPage.js137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtTagGalleryPage.js b/src/content/dependencies/generateArtTagGalleryPage.js
new file mode 100644
index 00000000..138189e1
--- /dev/null
+++ b/src/content/dependencies/generateArtTagGalleryPage.js
@@ -0,0 +1,137 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: [
+    'generateColorStyleRules',
+    'generateCoverGrid',
+    'generatePageLayout',
+    'image',
+    'linkAlbum',
+    'linkArtTag',
+    'linkTrack',
+  ],
+
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({wikiInfo}) {
+    return {
+      enableListings: wikiInfo.enableListings,
+    };
+  },
+
+  query(sprawl, tag) {
+    const things = tag.taggedInThings.slice();
+
+    sortAlbumsTracksChronologically(things, {
+      getDate: thing => thing.coverArtDate,
+      latestFirst: true,
+    });
+
+    return {things};
+  },
+
+  relations(relation, query, sprawl, tag) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    relations.colorStyleRules =
+      relation('generateColorStyleRules', tag.color);
+
+    relations.artTagMainLink =
+      relation('linkArtTag', tag);
+
+    relations.coverGrid =
+      relation('generateCoverGrid');
+
+    relations.links =
+      query.things.map(thing =>
+        (thing.album
+          ? relation('linkTrack', thing)
+          : relation('linkAlbum', thing)));
+
+    relations.images =
+      query.things.map(thing =>
+        relation('image', thing.artTags));
+
+    return relations;
+  },
+
+  data(query, sprawl, artist) {
+    const data = {};
+
+    data.enableListings = sprawl.enableListings;
+
+    data.name = artist.name;
+
+    data.numArtworks = query.things.length;
+
+    data.names =
+      query.things.map(thing => thing.name);
+
+    data.paths =
+      query.things.map(thing =>
+        (thing.album
+          ? ['media.trackCover', thing.album.directory, thing.directory, thing.coverArtFileExtension]
+          : ['media.albumCover', thing.directory, thing.coverArtFileExtension]));
+
+    return data;
+  },
+
+  generate(data, relations, {html, language}) {
+    return relations.layout
+      .slots({
+        title:
+          language.$('tagPage.title', {
+            tag: data.name,
+          }),
+
+        headingMode: 'static',
+
+        colorStyleRules: [relations.colorStyleRules],
+
+        mainClasses: ['top-index'],
+        mainContent: [
+          html.tag('p',
+            {class: 'quick-info'},
+            language.$('tagPage.infoLine', {
+              coverArts: language.countCoverArts(data.numArtworks, {
+                unit: true,
+              }),
+            })),
+
+          relations.coverGrid
+            .slots({
+              links: relations.links,
+              names: data.names,
+              images:
+                stitchArrays({
+                  image: relations.images,
+                  path: data.paths,
+                }).map(({image, path}) =>
+                    image.slot('path', path)),
+            }),
+        ],
+
+        navLinkStyle: 'hierarchical',
+        navLinks: [
+          {auto: 'home'},
+
+          data.enableListings &&
+            {
+              path: ['localized.listingIndex'],
+              title: language.$('listingIndex.title'),
+            },
+
+          {
+            html:
+              language.$('tagPage.nav.tag', {
+                tag: relations.artTagMainLink,
+              }),
+          },
+        ],
+      });
+  },
+};