« get me outta code hell

content: generateGroupGalleryPageAlbumGridTab (factor out) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-07-25 04:45:02 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-07-25 04:45:02 -0300
commit39dfd7bb398adf3c6e4aee6a5bc56fff2098a24c (patch)
treebb22f9b8703fa12417047c9e50f068f2bd1cc172 /src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js
parent41186f67936dc2fd193dc9ad281403b660f9b911 (diff)
content: generateGroupGalleryPageAlbumGridTab (factor out)
Diffstat (limited to 'src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js')
-rw-r--r--src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js b/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js
new file mode 100644
index 00000000..597c5227
--- /dev/null
+++ b/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js
@@ -0,0 +1,60 @@
+import {empty} from '#sugar';
+
+export default {
+  contentDependencies: ['generateArtistCredit'],
+  extraDependencies: ['language'],
+
+  query(album, group) {
+    const query = {};
+
+    const contextGroup = group;
+
+    const candidateGroups =
+      album.groups
+        .filter(group => !group.excludeFromGalleryTabs)
+        .filter(group => group.category !== contextGroup.category);
+
+    query.notedGroup = candidateGroups.at(0) ?? null;
+
+    if (
+      album.artistContribs.length === 1 &&
+      !empty(group.closelyLinkedArtists) &&
+      (album.artistContribs[0].artist.name ===
+       group.closelyLinkedArtists[0].artist.name)
+    ) {
+      query.notedArtistContribs = [];
+    } else {
+      query.notedArtistContribs = album.artistContribs;
+    }
+
+    return query;
+  },
+
+  relations: (relation, query, _album, _group) => ({
+    artistCredit:
+      relation('generateArtistCredit', query.notedArtistContribs, []),
+  }),
+
+  data: (query, _album, _group) => ({
+    groupName:
+      (query.notedGroup
+        ? query.notedGroup.name
+        : null),
+  }),
+
+  generate: (data, relations, {language}) =>
+    language.encapsulate('misc.coverGrid.tab', capsule =>
+      (data.groupName
+        ? language.$(capsule, 'group', {
+            group: data.groupName,
+          })
+     : relations.artistCredit
+        ? relations.artistCredit.slots({
+            normalStringKey:
+              capsule + '.artists',
+
+            normalFeaturingStringKey:
+              capsule + '.artists.featuring',
+          })
+        : null)),
+};