« get me outta code hell

content: gAIPTracksChunk: consider contributions from main release - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageTracksChunk.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-01-11 17:31:16 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-01-11 17:31:16 -0400
commitcd6c3ebdb20ecee2944f0de1cfbed5a24a924cc5 (patch)
treec0e262e3ae1fa18ae783c9916d67c9be76e14930 /src/content/dependencies/generateArtistInfoPageTracksChunk.js
parentc563105424cc8a25918e169e9f2121771723b2c2 (diff)
content: gAIPTracksChunk: consider contributions from main release
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageTracksChunk.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunk.js39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
index ce8b284b..50278271 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunk.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
@@ -2,21 +2,44 @@ import {sortAlbumsTracksChronologically} from '#sort';
 import {empty, unique} from '#sugar';
 import {getTotalDuration} from '#wiki-data';
 
+function countTowardTotals(contribs) {
+  const track = contribs[0].thing;
+
+  if (track.isSecondaryRelease) {
+    const all =
+      Object.fromEntries(
+        unique(contribs.map(contrib => contrib.thingProperty))
+          .map(prop => [
+            prop,
+            track.mainReleaseTrack[prop].slice(),
+          ]));
+
+    contribs = contribs.flatMap(a => {
+      const array = all[a.thingProperty];
+      const index =
+        array.findIndex(b =>
+          b.artist === a.artist &&
+          b.annotation === a.annotation);
+
+      if (index === -1) return [];
+      return array.splice(index, 1);
+    }).filter(Boolean);
+  }
+
+  return contribs.some(contrib =>
+    contrib.countInContributionTotals ||
+    contrib.countInDurationTotals);
+}
+
 export default {
   query: (_artist, _album, trackContribLists) => ({
     contribListsCountingTowardTotals:
       trackContribLists
-        .filter(trackContribs => trackContribs
-          .some(contrib =>
-            contrib.countInContributionTotals ||
-            contrib.countInDurationTotals)),
+        .filter(contribs => countTowardTotals(contribs)),
 
     contribListsNotCountingTowardTotals:
       trackContribLists
-        .filter(trackContribs => trackContribs
-          .every(contrib =>
-            !contrib.countInContributionTotals &&
-            !contrib.countInDurationTotals)),
+        .filter(contribs => !countTowardTotals(contribs)),
   }),
 
   relations: (relation, query, artist, album, _trackContribLists) => ({