« 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/generateArtistInfoPageChunk.js
diff options
context:
space:
mode:
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 00000000..121cf43d
--- /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)),
+    ]);
+  },
+};