« get me outta code hell

content: generateArtistGalleryPage: move galleryThings into query - 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:12:08 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-15 19:12:08 -0300
commitb493cc4b426910ecfa662f904bc0e01fee236c7a (patch)
tree86eae89f70e27889f25d60bd24f22ec4631696c7 /src/content
parentb34828921179b53434db4fa93a72dd52e5f72fa5 (diff)
content: generateArtistGalleryPage: move galleryThings into query
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateArtistGalleryPage.js31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/content/dependencies/generateArtistGalleryPage.js b/src/content/dependencies/generateArtistGalleryPage.js
index d1ec3efe..98fa2dcb 100644
--- a/src/content/dependencies/generateArtistGalleryPage.js
+++ b/src/content/dependencies/generateArtistGalleryPage.js
@@ -1,13 +1,6 @@
 import {stitchArrays} from '../../util/sugar.js';
 import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js';
 
-// TODO: Very awkward we have to duplicate this functionality in relations and data.
-function getGalleryThings(artist) {
-  const galleryThings = [...artist.albumsAsCoverArtist, ...artist.tracksAsCoverArtist];
-  sortAlbumsTracksChronologically(galleryThings, {latestFirst: true});
-  return galleryThings;
-}
-
 export default {
   contentDependencies: [
     'generateArtistNavLinks',
@@ -20,7 +13,13 @@ export default {
 
   extraDependencies: ['html', 'language'],
 
-  relations(relation, artist) {
+  query(artist) {
+    const things = [...artist.albumsAsCoverArtist, ...artist.tracksAsCoverArtist];
+    sortAlbumsTracksChronologically(things, {latestFirst: true});
+    return {things};
+  },
+
+  relations(relation, query, artist) {
     const relations = {};
 
     relations.layout =
@@ -32,35 +31,31 @@ export default {
     relations.coverGrid =
       relation('generateCoverGrid');
 
-    const galleryThings = getGalleryThings(artist);
-
     relations.links =
-      galleryThings.map(thing =>
+      query.things.map(thing =>
         (thing.album
           ? relation('linkTrack', thing)
           : relation('linkAlbum', thing)));
 
     relations.images =
-      galleryThings.map(thing =>
+      query.things.map(thing =>
         relation('image', thing.artTags));
 
     return relations;
   },
 
-  data(artist) {
+  data(query, artist) {
     const data = {};
 
     data.name = artist.name;
 
-    const galleryThings = getGalleryThings(artist);
-
-    data.numArtworks = galleryThings.length;
+    data.numArtworks = query.things.length;
 
     data.names =
-      galleryThings.map(thing => thing.name);
+      query.things.map(thing => thing.name);
 
     data.paths =
-      galleryThings.map(thing =>
+      query.things.map(thing =>
         (thing.album
           ? ['media.trackCover', thing.album.directory, thing.directory, thing.coverArtFileExtension]
           : ['media.albumCover', thing.directory, thing.coverArtFileExtension]));