« get me outta code hell

content: generateArtistInfoPage rewrite draft - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageChunkItem.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-26 00:23:58 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-26 00:24:46 -0300
commit1deb589b2e22d92f6488d259ce6196706f1515b1 (patch)
treecf2167ffdcdbc91d5ec18b26dd2c9848846cee57 /src/content/dependencies/generateArtistInfoPageChunkItem.js
parent3f6f40765018b70e8106a210b4553b26f8f64d13 (diff)
content: generateArtistInfoPage rewrite draft
Rewriting a rewrite!? Say whaaaaat???

Sorry, the previous code didn't even come close to snuff.
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageChunkItem.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageChunkItem.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageChunkItem.js b/src/content/dependencies/generateArtistInfoPageChunkItem.js
new file mode 100644
index 00000000..9004f18a
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageChunkItem.js
@@ -0,0 +1,50 @@
+export default {
+  extraDependencies: ['html', 'language'],
+
+  slots: {
+    content: {type: 'html'},
+
+    otherArtistLinks: {validate: v => v.arrayOf(v.isHTML)},
+    contribution: {type: 'string'},
+    rerelease: {type: 'boolean'},
+  },
+
+  generate(slots, {html, language}) {
+    let accentedContent = slots.content;
+
+    accent: {
+      if (slots.rerelease) {
+        accentedContent =
+          language.$('artistPage.creditList.entry.rerelease', {
+            entry: accentedContent,
+          });
+
+        break accent;
+      }
+
+      const parts = ['artistPage.creditList.entry'];
+      const options = {entry: accentedContent};
+
+      if (slots.otherArtistLinks) {
+        parts.push('withArtists');
+        options.artists = language.formatConjunctionList(slots.otherArtistLinks);
+      }
+
+      if (slots.contribution) {
+        parts.push('withContribution');
+        options.contribution = slots.contribution;
+      }
+
+      if (parts.length === 1) {
+        break accent;
+      }
+
+      accentedContent = language.formatString(parts.join('.'), options);
+    }
+
+    return (
+      html.tag('li',
+        {class: slots.rerelease && 'rerelease'},
+        accentedContent));
+  },
+};