« 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/generateArtistInfoPageChunk.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/generateArtistInfoPageChunk.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/generateArtistInfoPageChunk.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageChunk.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageChunk.js b/src/content/dependencies/generateArtistInfoPageChunk.js
new file mode 100644
index 0000000..121cf43
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageChunk.js
@@ -0,0 +1,44 @@
+export default {
+  extraDependencies: ['html', 'language'],
+
+  slots: {
+    albumLink: {type: 'html'},
+
+    date: {validate: v => v.isDate},
+    duration: {validate: v => v.isDuration},
+    durationApproximate: {type: 'boolean'},
+
+    items: {type: 'html'},
+  },
+
+  generate(slots, {html, language}) {
+    let accentedLink = slots.albumLink;
+
+    accent: {
+      const options = {album: accentedLink};
+      const parts = ['artistPage.creditList.album'];
+
+      if (slots.date) {
+        parts.push('withDate');
+        options.date = language.formatDate(slots.date);
+      }
+
+      if (slots.duration) {
+        parts.push('withDuration');
+        options.duration =
+          language.formatDuration(slots.duration, {
+            approximate: slots.durationApproximate,
+          });
+      }
+
+      accentedLink = language.formatString(parts.join('.'), options);
+    }
+
+    return html.tags([
+      html.tag('dt', accentedLink),
+      html.tag('dd',
+        html.tag('ul',
+          slots.items)),
+    ]);
+  },
+};