« get me outta code hell

content: generateTrackList (generic function) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackList.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-18 21:23:40 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-18 21:25:08 -0300
commit07df83cb011400c499fc5ff859ba7bf5795553ed (patch)
treeac88eaec03572321a5a3541b4d006ef2b450b75e /src/content/dependencies/generateTrackList.js
parentfba7d3d6e6d4271744e66efa101d98777995d878 (diff)
content: generateTrackList (generic function)
This isn't quite portable enough for use as a dependency
in generateAlbumTrackList, which can maybe be improved on.
Diffstat (limited to 'src/content/dependencies/generateTrackList.js')
-rw-r--r--src/content/dependencies/generateTrackList.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTrackList.js b/src/content/dependencies/generateTrackList.js
new file mode 100644
index 0000000..e2e9f48
--- /dev/null
+++ b/src/content/dependencies/generateTrackList.js
@@ -0,0 +1,55 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['linkTrack', 'linkContribution'],
+
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, tracks) {
+    if (empty(tracks)) {
+      return {};
+    }
+
+    return {
+      items: tracks.map(track => ({
+        trackLink:
+          relation('linkTrack', track),
+
+        contributionLinks:
+          track.artistContribs.map(contrib =>
+            relation('linkContribution', contrib.who, contrib.what)),
+      })),
+    };
+  },
+
+  generate(relations, {html, language}) {
+    return html.template({
+      annotation: `generateTrackList`,
+
+      slots: {
+        showContribution: {type: 'boolean', default: false},
+        showIcons: {type: 'boolean', default: false},
+      },
+
+      content(slots) {
+        return html.tag('ul',
+          relations.items.map(({trackLink, contributionLinks}) =>
+            html.tag('li',
+              language.$('trackList.item.withArtists', {
+                track: trackLink,
+                by:
+                  html.tag('span', {class: 'by'},
+                    language.$('trackList.item.withArtists.by', {
+                      artists:
+                        language.formatConjunctionList(
+                          contributionLinks.map(link =>
+                            link.slots({
+                              showContribution: slots.showContribution,
+                              showIcons: slots.showIcons,
+                            }))),
+                    })),
+              }))));
+      },
+    });
+  },
+};