« get me outta code hell

content: generateMusicVideoReleaseLine: wrap "by" nicely - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-01-17 05:06:34 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-01-17 05:06:34 -0400
commita0381a363e0ee05d2aa78316b5a910ac749fc101 (patch)
tree2c336c5e6d38de1d97add9b9e7ba9a3690afe62f /src/content
parentda43a2365d18216a6fc54f073b7ec85cc4e7dafc (diff)
content: generateMusicVideoReleaseLine: wrap "by" nicely
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateMusicVideo.js52
-rw-r--r--src/content/dependencies/generateMusicVideoReleaseLine.js61
2 files changed, 77 insertions, 36 deletions
diff --git a/src/content/dependencies/generateMusicVideo.js b/src/content/dependencies/generateMusicVideo.js
index 7f0108af..e83fdf80 100644
--- a/src/content/dependencies/generateMusicVideo.js
+++ b/src/content/dependencies/generateMusicVideo.js
@@ -7,11 +7,8 @@ export default {
         dimensions: musicVideo.coverArtDimensions,
       }),
 
-    datetimestamp:
-      relation('generateAbsoluteDatetimestamp', musicVideo.date, thing.date),
-
-    artistCredit:
-      relation('generateArtistCredit', musicVideo.artistContribs, []),
+    releaseLine:
+      relation('generateMusicVideoReleaseLine', musicVideo, thing),
 
     contributorCredit:
       relation('generateArtistCredit', musicVideo.contributorContribs, []),
@@ -48,42 +45,25 @@ export default {
           {[html.joinChildren]: html.tag('br')},
 
           [
-            language.encapsulate(capsule, 'by', workingCapsule => {
-              const workingOptions = {};
-
-              if (data.label) {
-                workingCapsule += '.customLabel';
-                workingOptions.label = data.label;
-              }
-
-              const {datetimestamp} = relations;
-
-              datetimestamp.setSlot('style', 'year-difference');
-
-              if (!html.isBlank(datetimestamp)) {
-                workingCapsule += '.withDate';
-                workingOptions.date = datetimestamp;
-              }
-
-              return relations.artistCredit.slots({
-                normalStringKey: workingCapsule,
-                additionalStringOptions: workingOptions,
+            html.tag('span', {class: 'release-line'},
+              {[html.onlyIfContent]: true},
 
-                showAnnotation: true,
-                showChronology: true,
+              relations.releaseLine),
 
-                chronologyKind: 'musicVideo',
-              });
-            }),
+            language.encapsulate(capsule, 'contributorsLine', capsule =>
+              language.$(capsule, {
+                [language.onlyIfOptions]: ['credit'],
 
-            relations.contributorCredit.slots({
-              normalStringKey: language.encapsulate(capsule, 'contributors'),
+                credit:
+                  relations.contributorCredit.slots({
+                    normalStringKey: language.encapsulate(capsule, 'credit'),
 
-              showAnnotation: true,
-              showChronology: true,
+                    showAnnotation: true,
+                    showChronology: true,
 
-              chronologyKind: 'musicVideoContribution',
-            }),
+                    chronologyKind: 'musicVideoContribution',
+                  }),
+              })),
           ]),
       ])),
 };
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();
+  },
+}