« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateReleaseInfoContributionsLine.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateReleaseInfoContributionsLine.js')
-rw-r--r--src/content/dependencies/generateReleaseInfoContributionsLine.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/content/dependencies/generateReleaseInfoContributionsLine.js b/src/content/dependencies/generateReleaseInfoContributionsLine.js
new file mode 100644
index 00000000..2b342d09
--- /dev/null
+++ b/src/content/dependencies/generateReleaseInfoContributionsLine.js
@@ -0,0 +1,49 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['linkContribution'],
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, contributions) {
+    if (empty(contributions)) {
+      return {};
+    }
+
+    return {
+      contributionLinks:
+        contributions
+          .slice(0, 4)
+          .map(({who, what}) =>
+            relation('linkContribution', who, what)),
+    };
+  },
+
+  generate(relations, {html, language}) {
+    return html.template({
+      annotation: `generateReleaseInfoContributionsLine`,
+
+      slots: {
+        stringKey: {type: 'string'},
+
+        showContribution: {type: 'boolean', default: true},
+        showIcons: {type: 'boolean', default: true},
+      },
+
+      content(slots) {
+        if (!relations.contributionLinks) {
+          return html.blank();
+        }
+
+        return language.$(slots.stringKey, {
+          artists:
+            language.formatConjunctionList(
+              relations.contributionLinks.map(link =>
+                link.slots({
+                  showContribution: slots.showContribution,
+                  showIcons: slots.showIcons,
+                }))),
+        });
+      },
+    });
+  },
+};