« get me outta code hell

content: generateAlbumSidebar: move group boxes into own function - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumSidebarGroupBox.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-02 13:34:45 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-02 13:40:51 -0300
commitd5122a2657cbf1e39c674e47788cd1e16fdeaed9 (patch)
tree4408e5d8364e68a76ca9eb312f65e8097979705d /src/content/dependencies/generateAlbumSidebarGroupBox.js
parent07df83cb011400c499fc5ff859ba7bf5795553ed (diff)
content: generateAlbumSidebar: move group boxes into own function
This will make for cleaner dependencies and finer-grained refreshing.
Diffstat (limited to 'src/content/dependencies/generateAlbumSidebarGroupBox.js')
-rw-r--r--src/content/dependencies/generateAlbumSidebarGroupBox.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/content/dependencies/generateAlbumSidebarGroupBox.js b/src/content/dependencies/generateAlbumSidebarGroupBox.js
new file mode 100644
index 0000000..0679e8f
--- /dev/null
+++ b/src/content/dependencies/generateAlbumSidebarGroupBox.js
@@ -0,0 +1,82 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['linkAlbum', 'linkExternal', 'linkGroup'],
+  extraDependencies: ['html', 'language', 'transformMultiline'],
+
+  relations(relation, album, group) {
+    const relations = {};
+
+    relations.groupLink =
+      relation('linkGroup', group);
+
+    relations.externalLinks =
+      group.urls.map(url =>
+        relation('linkExternal', url));
+
+    const albums = group.albums.filter(album => album.date);
+    const index = albums.indexOf(album);
+    const previousAlbum = (index > 0) && albums[index - 1];
+    const nextAlbum = (index < albums.length - 1) && albums[index + 1];
+
+    if (previousAlbum) {
+      relations.previousAlbumLink =
+        relation('linkAlbum', previousAlbum);
+    }
+
+    if (nextAlbum) {
+      relations.nextAlbumLink =
+        relation('linkAlbum', nextAlbum);
+    }
+
+    return relations;
+  },
+
+  data(album, group) {
+    return {
+      description: group.descriptionShort,
+    };
+  },
+
+  generate(data, relations, {html, language, transformMultiline}) {
+    return html.template({
+      annotation: `generateAlbumSidebarGroupBox`,
+
+      slots: {
+        isAlbumPage: {type: 'boolean', default: false},
+      },
+
+      content(slots) {
+        return html.tags([
+          html.tag('h1',
+            language.$('albumSidebar.groupBox.title', {
+              group: relations.groupLink,
+            })),
+
+          slots.isAlbumPage &&
+            transformMultiline(data.description),
+
+          !empty(relations.externalLinks) &&
+            html.tag('p',
+              language.$('releaseInfo.visitOn', {
+                links: language.formatDisjunctionList(relations.externalLinks),
+              })),
+
+          slots.isAlbumPage &&
+          relations.nextAlbumLink &&
+            html.tag('p', {class: 'group-chronology-link'},
+              language.$('albumSidebar.groupBox.next', {
+                album: relations.nextAlbumLink,
+              })),
+
+          slots.isAlbumPage &&
+          relations.previousAlbumLink &&
+            html.tag('p', {class: 'group-chronology-link'},
+              language.$('albumSidebar.groupBox.previous', {
+                album: relations.previousAlbumLink,
+              })),
+        ]);
+      },
+    });
+  },
+};