« get me outta code hell

search: don't expose group names if they match an artist name - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-13 11:40:16 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:53 -0300
commitdb2ebb010aada0739773769cbaf3c34a9763c1fd (patch)
treee8ecd6423a85156b156b439f542edd33808efd57
parentb69e03084d142f530879a063f4844b1ee432e37a (diff)
search: don't expose group names if they match an artist name
-rw-r--r--src/util/search-spec.js32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/util/search-spec.js b/src/util/search-spec.js
index dc58b276..7e5b2b63 100644
--- a/src/util/search-spec.js
+++ b/src/util/search-spec.js
@@ -133,19 +133,33 @@ export const searchSpec = {
         'wallpaperArtistContribs',
       ];
 
-      fields.contributors =
+      const contributions =
         contribKeys
           .filter(key => Object.hasOwn(thing, key))
-          .flatMap(key => thing[key])
-          .map(contrib => contrib.artist)
-          .flatMap(artist => [artist.name, ...artist.aliasNames]);
+          .flatMap(key => thing[key]);
+
+      fields.contributors =
+        contributions
+          .flatMap(({artist}) => [
+            artist.name,
+            ...artist.aliasNames,
+          ]);
+
+      const groups =
+         (Object.hasOwn(thing, 'groups')
+           ? thing.groups
+        : Object.hasOwn(thing, 'album')
+           ? thing.album.groups
+           : []);
+
+      const mainContributorNames =
+        contributions
+          .map(({artist}) => artist.name);
 
       fields.groups =
-        (Object.hasOwn(thing, 'groups')
-          ? thing.groups.map(group => group.name)
-       : Object.hasOwn(thing, 'album')
-          ? thing.album.groups.map(group => group.name)
-          : []);
+        groups
+          .filter(group => !mainContributorNames.includes(group.name))
+          .map(group => group.name);
 
       fields.artwork =
         prepareArtwork(thing, opts);