« get me outta code hell

content: generateGroupInfoPage: content function syntax cleanup - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateGroupInfoPageAlbumsSection.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-12 15:16:23 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:10 -0300
commitb0b50b839025b2e344c0ff968f9e0e498b839b43 (patch)
tree7c71c27bbeebf24d8fc3afe454803b7ceb39c183 /src/content/dependencies/generateGroupInfoPageAlbumsSection.js
parent3d7594501f2894bbd869a09b67df5258555aa972 (diff)
content: generateGroupInfoPage: content function syntax cleanup
Diffstat (limited to 'src/content/dependencies/generateGroupInfoPageAlbumsSection.js')
-rw-r--r--src/content/dependencies/generateGroupInfoPageAlbumsSection.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/content/dependencies/generateGroupInfoPageAlbumsSection.js b/src/content/dependencies/generateGroupInfoPageAlbumsSection.js
new file mode 100644
index 00000000..d1dab542
--- /dev/null
+++ b/src/content/dependencies/generateGroupInfoPageAlbumsSection.js
@@ -0,0 +1,132 @@
+import {empty} from '#sugar';
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateAbsoluteDatetimestamp',
+    'generateColorStyleAttribute',
+    'generateContentHeading',
+    'linkAlbum',
+    'linkGroupGallery',
+    'linkGroup',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query(group) {
+    const albums =
+      group.albums;
+
+    const albumGroups =
+      albums
+        .map(album => album.groups);
+
+    const albumOtherCategory =
+      albumGroups
+        .map(groups => groups
+          .map(group => group.category)
+          .find(category => category !== group.category));
+
+    const albumOtherGroups =
+      stitchArrays({
+        groups: albumGroups,
+        category: albumOtherCategory,
+      }).map(({groups, category}) =>
+          groups
+            .filter(group => group.category === category));
+
+    return {albums, albumOtherGroups};
+  },
+
+  relations: (relation, query, group) => ({
+    contentHeading:
+      relation('generateContentHeading'),
+
+    galleryLink:
+      relation('linkGroupGallery', group),
+
+    albumColorStyles:
+      query.albums
+        .map(album => relation('generateColorStyleAttribute', album.color)),
+
+    albumLinks:
+      query.albums
+        .map(album => relation('linkAlbum', album)),
+
+    otherGroupLinks:
+      query.albumOtherGroups
+        .map(groups => groups
+          .map(group => relation('linkGroup', group))),
+
+    datetimestamps:
+      group.albums.map(album =>
+        (album.date
+          ? relation('generateAbsoluteDatetimestamp', album.date)
+          : null)),
+  }),
+
+  generate: (relations, {html, language}) =>
+    html.tags([
+      relations.contentHeading
+        .slots({
+          tag: 'h2',
+          title: language.$('groupInfoPage.albumList.title'),
+        }),
+
+      html.tag('p',
+        {[html.onlyIfSiblings]: true},
+        language.$('groupInfoPage.viewAlbumGallery', {
+          link:
+            relations.galleryLink
+              .slot('content', language.$('groupInfoPage.viewAlbumGallery.link')),
+        })),
+
+      html.tag('ul',
+        {[html.onlyIfContent]: true},
+
+        stitchArrays({
+          albumLink: relations.albumLinks,
+          otherGroupLinks: relations.otherGroupLinks,
+          datetimestamp: relations.datetimestamps,
+          albumColorStyle: relations.albumColorStyles,
+        }).map(({
+            albumLink,
+            otherGroupLinks,
+            datetimestamp,
+            albumColorStyle,
+          }) => {
+            const prefix = 'groupInfoPage.albumList.item';
+            const parts = [prefix];
+            const options = {};
+
+            options.album =
+              albumLink.slot('color', false);
+
+            if (datetimestamp) {
+              parts.push('withYear');
+              options.yearAccent =
+                language.$(prefix, 'yearAccent', {
+                  year:
+                    datetimestamp.slots({style: 'year', tooltip: true}),
+                });
+            }
+
+            if (!empty(otherGroupLinks)) {
+              parts.push('withOtherGroup');
+              options.otherGroupAccent =
+                html.tag('span', {class: 'other-group-accent'},
+                  language.$(prefix, 'otherGroupAccent', {
+                    groups:
+                      language.formatConjunctionList(
+                        otherGroupLinks.map(groupLink =>
+                          groupLink.slot('color', false))),
+                  }));
+            }
+
+            return (
+              html.tag('li',
+                albumColorStyle,
+                language.$(...parts, options)));
+          })),
+    ]),
+};