« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/common-util/wiki-data.js13
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunk.js30
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js5
-rw-r--r--src/strings-default.yaml1
4 files changed, 38 insertions, 11 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js
index de34a807..c9c63db7 100644
--- a/src/common-util/wiki-data.js
+++ b/src/common-util/wiki-data.js
@@ -256,13 +256,18 @@ export function getArtistAvatar(artist, {to}) {
 // Used in multiple content functions for the artist info page,
 // because shared logic is torture oooooooooooooooo.
 export function chunkArtistTrackContributions(contributions) {
+  const date = contrib => contrib.date;
+
+  const album = contrib =>
+    (contrib.thing.isTrack
+      ? contrib.thing.album
+      : contrib.thing);
+
   return (
     // First chunk by (contribution) date and album.
     chunkByConditions(contributions, [
-      ({date: date1}, {date: date2}) =>
-        +date1 !== +date2,
-      ({thing: track1}, {thing: track2}) =>
-        track1.album !== track2.album,
+      (a, b) => +date(a) !== +date(b),
+      (a, b) => album(a) !== album(b),
     ]).map(contribs =>
         // Then, *within* the boundaries of the existing chunks,
         // chunk contributions to the same thing together.
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
index 50278271..fc5a617e 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunk.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
@@ -2,8 +2,11 @@ import {sortAlbumsTracksChronologically} from '#sort';
 import {empty, unique} from '#sugar';
 import {getTotalDuration} from '#wiki-data';
 
-function countTowardTotals(contribs) {
-  const track = contribs[0].thing;
+function countTowardTrackTotals(contribs) {
+  const {thing} = contribs[0];
+  const track = thing.isTrack ? thing : null;
+
+  if (!track) return null;
 
   if (track.isSecondaryRelease) {
     const all =
@@ -33,13 +36,19 @@ function countTowardTotals(contribs) {
 
 export default {
   query: (_artist, _album, trackContribLists) => ({
+    isAlbumArtist:
+      trackContribLists.flat()
+        .some(contrib =>
+          contrib.thingProperty === 'artistContribs' &&
+          contrib.thing.isAlbum),
+
     contribListsCountingTowardTotals:
       trackContribLists
-        .filter(contribs => countTowardTotals(contribs)),
+        .filter(contribs => countTowardTrackTotals(contribs) === true),
 
     contribListsNotCountingTowardTotals:
       trackContribLists
-        .filter(contribs => !countTowardTotals(contribs)),
+        .filter(contribs => countTowardTrackTotals(contribs) === false),
   }),
 
   relations: (relation, query, artist, album, _trackContribLists) => ({
@@ -52,6 +61,13 @@ export default {
     albumArtistCredit:
       relation('generateArtistCredit', album.artistContribs, []),
 
+    albumArtistOnlyItem:
+     (query.isAlbumArtist &&
+      empty(query.contribListsCountingTowardTotals) &&
+      empty(query.contribListsNotCountingTowardTotals)
+        ? relation('generateArtistInfoPageAlbumArtistOnlyChunkItem')
+        : null),
+
     itemsCountingTowardTotals:
       query.contribListsCountingTowardTotals.map(trackContribs =>
         relation('generateArtistInfoPageTracksChunkItem',
@@ -91,7 +107,9 @@ export default {
       durationTerms.length > 1;
 
     const tracks =
-      trackContribLists.map(contribs => contribs[0].thing);
+      trackContribLists
+        .map(contribs => contribs[0].thing)
+        .filter(thing => thing.isTrack);
 
     data.numLinkingOtherReleases =
       tracks.filter(track => {
@@ -150,6 +168,8 @@ export default {
             {class: 'offset-tooltips'},
 
           [
+            relations.albumArtistOnlyItem,
+
             relations.itemsCountingTowardTotals,
 
             !empty(relations.itemsCountingTowardTotals) &&
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index 15588ed3..9c8ca7e0 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -8,6 +8,7 @@ export default {
     const query = {};
 
     const allContributions = [
+      ...artist.albumArtistContributions,
       ...artist.trackArtistContributions,
       ...artist.trackContributorContributions,
     ];
@@ -21,8 +22,8 @@ export default {
 
     query.albums =
       query.contribs
-        .map(contribs =>
-          contribs[0][0].thing.album);
+        .map(contribs => contribs[0][0].thing)
+        .map(thing => thing.isTrack ? thing.album : thing);
 
     return query;
   },
diff --git a/src/strings-default.yaml b/src/strings-default.yaml
index 6921b8a4..672984ee 100644
--- a/src/strings-default.yaml
+++ b/src/strings-default.yaml
@@ -1402,6 +1402,7 @@ artistPage:
       #   credits too, and those entreis get the strings below.
 
       album:
+        albumArtistOnly: "Credited as album artist only—track credits vary"
         coverArt: "(cover art)"
         wallpaperArt: "(wallpaper art)"
         bannerArt: "(banner art)"