« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/strings-default.json5
4 files changed, 78 insertions, 14 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 =
diff --git a/src/strings-default.json b/src/strings-default.json
index a6614931..df9945cf 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -261,8 +261,9 @@
   "albumPage.socialEmbed.body.withTracks.withReleaseDate": "{TRACKS}. Released {DATE}.",
   "albumPage.socialEmbed.body.withDuration.withTracks.withReleaseDate": "{DURATION}, {TRACKS}. Released {DATE}.",
   "albumGalleryPage.title": "{ALBUM} - Gallery",
-  "albumGalleryPage.infoLine": "{TRACKS} totaling {DURATION}.",
-  "albumGalleryPage.infoLine.withDate": "{TRACKS} totaling {DURATION}. Released {DATE}.",
+  "albumGalleryPage.statsLine": "{TRACKS} totaling {DURATION}.",
+  "albumGalleryPage.statsLine.withDate": "{TRACKS} totaling {DURATION}. Released {DATE}.",
+  "albumGalleryPage.coverArtistsLine": "All track artwork by {ARTISTS}.",
   "albumCommentaryPage.title": "{ALBUM} - Commentary",
   "albumCommentaryPage.infoLine": "{WORDS} across {ENTRIES}.",
   "albumCommentaryPage.nav.album": "Album: {ALBUM}",