« 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/generateAlbumSecondaryNavSeriesPart.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateAlbumSecondaryNavSeriesPart.js')
-rw-r--r--src/content/dependencies/generateAlbumSecondaryNavSeriesPart.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/content/dependencies/generateAlbumSecondaryNavSeriesPart.js b/src/content/dependencies/generateAlbumSecondaryNavSeriesPart.js
new file mode 100644
index 00000000..4cba4cf3
--- /dev/null
+++ b/src/content/dependencies/generateAlbumSecondaryNavSeriesPart.js
@@ -0,0 +1,98 @@
+import {atOffset} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateColorStyleAttribute',
+    'generatePreviousNextLinks',
+    'linkAlbumDynamically',
+    'linkGroup',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query(series, album) {
+    const query = {};
+
+    const albums =
+      series.albums;
+
+    const currentIndex =
+      albums.indexOf(album);
+
+    query.previousAlbum =
+      atOffset(albums, currentIndex, -1);
+
+    query.nextAlbum =
+      atOffset(albums, currentIndex, +1);
+
+    return query;
+  },
+
+  relations: (relation, query, series, _album) => ({
+    groupLink:
+      relation('linkGroup', series.group),
+
+    colorStyle:
+      relation('generateColorStyleAttribute', series.group.color),
+
+    previousNextLinks:
+      relation('generatePreviousNextLinks'),
+
+    previousAlbumLink:
+      (query.previousAlbum
+        ? relation('linkAlbumDynamically', query.previousAlbum)
+        : null),
+
+    nextAlbumLink:
+      (query.nextAlbum
+        ? relation('linkAlbumDynamically', query.nextAlbum)
+        : null),
+  }),
+
+  data: (_query, series) => ({
+    name: series.name,
+  }),
+
+  slots: {
+    mode: {
+      validate: v => v.is('album', 'track'),
+      default: 'album',
+    },
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    html.tag('span',
+      {class: 'nav-link'},
+
+      relations.colorStyle
+        .slot('context', 'primary-only'),
+
+      language.encapsulate('albumSecondaryNav.series', workingCapsule => {
+        const workingOptions = {};
+
+        workingOptions.series =
+          relations.groupLink.slots({
+            attributes: {class: 'series'},
+            color: false,
+            content: language.sanitize(data.name),
+          });
+
+        if (slots.mode === 'album') {
+          const {previousNextLinks} = relations;
+
+          previousNextLinks.setSlots({
+            previousLink: relations.previousAlbumLink,
+            nextLink: relations.nextAlbumLink,
+            id: false,
+          });
+
+          if (!html.isBlank(previousNextLinks)) {
+            workingCapsule += '.withPreviousNext';
+            workingOptions.previousNext =
+              language.formatUnitList(previousNextLinks.content);
+          }
+        }
+
+        return language.$(workingCapsule, workingOptions);
+      })),
+};