« get me outta code hell

content: generateAlbumGalleryCoverArtistsLine - 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>2023-07-16 11:59:14 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-16 11:59:14 -0300
commitd278cc4537b247dbfb3ccf806b5065e1642c8cb4 (patch)
tree37145c1ed7a60152e11dcd81f59b6bfc9e72ca91 /src/content/dependencies
parentf238efbf84d262274c28c04c0881a5464caf6a03 (diff)
content: generateAlbumGalleryCoverArtistsLine
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js20
-rw-r--r--src/content/dependencies/generateAlbumGalleryPage.js65
-rw-r--r--src/content/dependencies/generateAlbumGalleryStatsLine.js (renamed from src/content/dependencies/generateAlbumGalleryInfoLine.js)2
3 files changed, 75 insertions, 12 deletions
diff --git a/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js b/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js
new file mode 100644
index 00000000..0c6d800b
--- /dev/null
+++ b/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js
@@ -0,0 +1,20 @@
+export default {
+  contentDependencies: ['linkArtistGallery'],
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, coverArtists) {
+    return {
+      coverArtistLinks:
+        coverArtists
+          .map(artist => relation('linkArtistGallery', artist)),
+    };
+  },
+
+  generate(relations, {html, language}) {
+    return (
+      html.tag('p', {class: 'quick-info'},
+        language.$('albumGalleryPage.coverArtistsLine', {
+          artists: relations.coverArtistLinks,
+        })));
+  },
+};
diff --git a/src/content/dependencies/generateAlbumGalleryPage.js b/src/content/dependencies/generateAlbumGalleryPage.js
index b39b4c80..c88d1768 100644
--- a/src/content/dependencies/generateAlbumGalleryPage.js
+++ b/src/content/dependencies/generateAlbumGalleryPage.js
@@ -1,8 +1,9 @@
-import {stitchArrays} from '../../util/sugar.js';
+import {compareArrays, stitchArrays} from '../../util/sugar.js';
 
 export default {
   contentDependencies: [
-    'generateAlbumGalleryInfoLine',
+    'generateAlbumGalleryCoverArtistsLine',
+    'generateAlbumGalleryStatsLine',
     'generateAlbumNavAccent',
     'generateAlbumStyleRules',
     'generateColorStyleRules',
@@ -15,7 +16,36 @@ export default {
 
   extraDependencies: ['html', 'language'],
 
-  relations(relation, album) {
+  query(album) {
+    const query = {};
+
+    const tracksWithUniqueCoverArt =
+      album.tracks
+        .filter(track => track.hasUniqueCoverArt);
+
+    // Don't display "all artwork by..." for albums where there's
+    // only one unique artwork in the first place.
+    if (tracksWithUniqueCoverArt.length > 1) {
+      const allCoverArtistArrays =
+        tracksWithUniqueCoverArt
+          .map(track => track.coverArtistContribs)
+          .map(contribs => contribs.map(contrib => contrib.who));
+
+      const allSameCoverArtists =
+        allCoverArtistArrays
+          .slice(1)
+          .every(artists => compareArrays(artists, allCoverArtistArrays[0]));
+
+      if (allSameCoverArtists) {
+        query.coverArtistsForAllTracks =
+          allCoverArtistArrays[0];
+      }
+    }
+
+    return query;
+  },
+
+  relations(relation, query, album) {
     const relations = {};
 
     relations.layout =
@@ -33,8 +63,13 @@ export default {
     relations.albumNavAccent =
       relation('generateAlbumNavAccent', album, null);
 
-    relations.infoLine =
-      relation('generateAlbumGalleryInfoLine', album);
+    relations.statsLine =
+      relation('generateAlbumGalleryStatsLine', album);
+
+    if (query.coverArtistsForAllTracks) {
+      relations.coverArtistsLine =
+        relation('generateAlbumGalleryCoverArtistsLine', query.coverArtistsForAllTracks);
+    }
 
     relations.coverGrid =
       relation('generateCoverGrid');
@@ -52,7 +87,7 @@ export default {
     return relations;
   },
 
-  data(album) {
+  data(query, album) {
     const data = {};
 
     data.name = album.name;
@@ -61,10 +96,17 @@ export default {
       album.tracks.map(track => track.name);
 
     data.coverArtists =
-      album.tracks.map(track =>
-        (track.hasUniqueCoverArt
-          ? track.coverArtistContribs.map(({who: artist}) => artist.name)
-          : null));
+      album.tracks.map(track => {
+        if (query.coverArtistsForAllTracks) {
+          return null;
+        }
+
+        if (track.hasUniqueCoverArt) {
+          return track.coverArtistContribs.map(({who: artist}) => artist.name);
+        }
+
+        return null;
+      });
 
     data.paths =
       album.tracks.map(track =>
@@ -90,7 +132,8 @@ export default {
 
         mainClasses: ['top-index'],
         mainContent: [
-          relations.infoLine,
+          relations.statsLine,
+          relations.coverArtistsLine,
 
           relations.coverGrid
             .slots({
diff --git a/src/content/dependencies/generateAlbumGalleryInfoLine.js b/src/content/dependencies/generateAlbumGalleryStatsLine.js
index d4bd4d75..df36084c 100644
--- a/src/content/dependencies/generateAlbumGalleryInfoLine.js
+++ b/src/content/dependencies/generateAlbumGalleryStatsLine.js
@@ -13,7 +13,7 @@ export default {
   },
 
   generate(data, {html, language}) {
-    const parts = ['albumGalleryPage.infoLine'];
+    const parts = ['albumGalleryPage.statsLine'];
     const options = {};
 
     options.tracks =