« get me outta code hell

content: generateAlbumTrackListItem: form string from parts - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-24 18:14:57 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-24 18:16:20 -0300
commit5bcc678e133d1b94fce5d51b333daf6c117bf28c (patch)
treef4322215cb3a5b86385821c7070d0a146b072535
parent004ff284cb54be664fd57337e3ab0a6ca8c607b3 (diff)
content: generateAlbumTrackListItem: form string from parts
-rw-r--r--src/content/dependencies/generateAlbumTrackListItem.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js
index 761a4b50..794c4201 100644
--- a/src/content/dependencies/generateAlbumTrackListItem.js
+++ b/src/content/dependencies/generateAlbumTrackListItem.js
@@ -37,28 +37,29 @@ export default {
   },
 
   generate(data, relations, {getColors, html, language}) {
-    const stringOpts = {
-      duration: language.formatDuration(data.duration),
-      track: relations.trackLink,
-    };
-
     let style;
+
     if (data.color) {
       const {primary} = getColors(data.color);
       style = `--primary-color: ${primary}`;
     }
 
-    return html.tag('li',
-      {style},
-      (!data.showArtists
-        ? language.$('trackList.item.withDuration', stringOpts)
-        : language.$('trackList.item.withDuration.withArtists', {
-            ...stringOpts,
-            by:
-              html.tag('span', {class: 'by'},
-                language.$('trackList.item.withArtists.by', {
-                  artists: language.formatConjunctionList(relations.contributionLinks),
-                })),
-          })));
+    const parts = ['trackList.item.withDuration'];
+    const options = {};
+
+    options.duration = language.formatDuration(data.duration);
+    options.track = relations.trackLink;
+
+    if (data.showArtists) {
+      parts.push('withArtists');
+      options.by =
+        html.tag('span', {class: 'by'},
+          language.$('trackList.item.withArtists.by', {
+            artists: language.formatConjunctionList(relations.contributionLinks),
+          }));
+    }
+
+    return html.tag('li', {style},
+      language.formatString(parts.join('.'), options));
   },
 };