« 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/generateMusicVideoReleaseLine.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateMusicVideoReleaseLine.js')
-rw-r--r--src/content/dependencies/generateMusicVideoReleaseLine.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/content/dependencies/generateMusicVideoReleaseLine.js b/src/content/dependencies/generateMusicVideoReleaseLine.js
new file mode 100644
index 00000000..dc11f584
--- /dev/null
+++ b/src/content/dependencies/generateMusicVideoReleaseLine.js
@@ -0,0 +1,61 @@
+export default {
+  relations: (relation, musicVideo, thing) => ({
+    datetimestamp:
+      relation('generateAbsoluteDatetimestamp', musicVideo.date, thing.date),
+
+    artistCredit:
+      relation('generateArtistCredit', musicVideo.artistContribs, []),
+  }),
+
+  data: (data) => ({
+    label:
+      (data.label !== 'Music video'
+        ? data.label
+        : null),
+  }),
+
+  generate(data, relations, {html, language}) {
+    const {artistCredit, datetimestamp} = relations;
+    const capsule = language.encapsulate('misc.musicVideo');
+
+    datetimestamp.setSlot('style', 'year-difference');
+
+    let artistsLineCapsule = language.encapsulate(capsule, 'artistsLine');
+    let artistsLineOptions = {[language.onlyIfOptions]: ['credit']};
+
+    if (data.label) {
+      artistsLineCapsule += '.customLabel';
+      artistsLineOptions.label = data.label;
+    }
+
+    if (!html.isBlank(datetimestamp)) {
+      artistsLineCapsule += '.withDate';
+      artistsLineOptions.date = datetimestamp;
+    }
+
+    artistsLineOptions.credit =
+      html.tag('span', {class: 'by'},
+        {[html.onlyIfContent]: true},
+
+        artistCredit.slots({
+          normalStringKey: language.encapsulate(capsule, 'artistsLine.credit'),
+
+          showAnnotation: true,
+          showChronology: true,
+
+          chronologyKind: 'musicVideo',
+        }));
+
+    const artistsLine = language.$(artistsLineCapsule, artistsLineOptions);
+
+    if (!html.isBlank(artistsLine)) {
+      return artistsLine;
+    }
+
+    if (!html.isBlank(datetimestamp)) {
+      return language.$(capsule, 'date', {date: datetimestamp});
+    }
+
+    return html.blank();
+  },
+}