« 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/generateGroupInfoPageAlbumsListBySeries.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateGroupInfoPageAlbumsListBySeries.js')
-rw-r--r--src/content/dependencies/generateGroupInfoPageAlbumsListBySeries.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/content/dependencies/generateGroupInfoPageAlbumsListBySeries.js b/src/content/dependencies/generateGroupInfoPageAlbumsListBySeries.js
new file mode 100644
index 00000000..8fa90877
--- /dev/null
+++ b/src/content/dependencies/generateGroupInfoPageAlbumsListBySeries.js
@@ -0,0 +1,54 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateContentHeading',
+    'generateGroupInfoPageAlbumsListItem',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, group) => ({
+    seriesHeadings:
+      group.serieses
+        .map(() => relation('generateContentHeading')),
+
+    seriesItems:
+      group.serieses
+        .map(series => series.albums
+          .map(album =>
+            relation('generateGroupInfoPageAlbumsListItem',
+              album,
+              group))),
+  }),
+
+  data: (group) => ({
+    seriesNames:
+      group.serieses
+        .map(series => series.name),
+  }),
+
+  generate: (data, relations, {html, language}) =>
+    language.encapsulate('groupInfoPage.albumList', listCapsule =>
+      html.tag('dl', {class: 'group-series-list'},
+        {[html.onlyIfContent]: true},
+
+        stitchArrays({
+          name: data.seriesNames,
+          heading: relations.seriesHeadings,
+          items: relations.seriesItems,
+        }).map(({heading, name, items}) =>
+            html.tags([
+              heading.slots({
+                tag: 'dt',
+                title:
+                  language.$(listCapsule, 'series', {
+                    series: name,
+                  }),
+              }),
+
+              html.tag('dd',
+                html.tag('ul',
+                  items)),
+            ])))),
+};