« get me outta code hell

getChronologyRelations: filter out duplicate artists - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-18 19:07:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-18 19:07:27 -0300
commit4fe9bfe3b653da593fa142eeb89d92f262680d8c (patch)
tree83d3072c43e4c045958794fc6df9d1da140f1097 /src/content/util
parent3abf558aa3d9ffeb5a6516b750880f7d4b0ab3de (diff)
getChronologyRelations: filter out duplicate artists
Only within the same call, so an artist who is both composer
and cover artist will still be listed in the chronology section
twice ("45th track by rj!" + "15th cover art by rj!").
This commit includes a documentation block about that.
Diffstat (limited to 'src/content/util')
-rw-r--r--src/content/util/getChronologyRelations.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/content/util/getChronologyRelations.js b/src/content/util/getChronologyRelations.js
index 4b7d9ce5..11281e75 100644
--- a/src/content/util/getChronologyRelations.js
+++ b/src/content/util/getChronologyRelations.js
@@ -4,6 +4,29 @@ export default function getChronologyRelations(thing, {
   linkThing,
   getThings,
 }) {
+  // One call to getChronologyRelations is considered "lumping" together all
+  // contributions as carrying equivalent meaning (for example, "artist"
+  // contributions and "contributor" contributions are bunched together in
+  // one call to getChronologyRelations, while "cover artist" contributions
+  // are a separate call). getChronologyRelations prevents duplicates that
+  // carry the same meaning by only using the first instance of each artist
+  // in the contributions array passed to it. It's expected that the string
+  // identifying which kind of contribution ("track" or "cover art") is
+  // shared and applied to all contributions, as providing them together
+  // in one call to getChronologyRelations implies they carry the same
+  // meaning.
+
+  const artistsSoFar = new Set();
+
+  contributions = contributions.filter(({who}) => {
+    if (artistsSoFar.has(who)) {
+      return false;
+    } else {
+      artistsSoFar.add(who);
+      return true;
+    }
+  });
+
   return contributions.map(({who}) => {
     const things = Array.from(new Set(getThings(who)));
     const index = things.indexOf(thing);