« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateAlbumArtInfoBox.js118
1 files changed, 98 insertions, 20 deletions
diff --git a/src/content/dependencies/generateAlbumArtInfoBox.js b/src/content/dependencies/generateAlbumArtInfoBox.js
index 5491192a..a3b4c02d 100644
--- a/src/content/dependencies/generateAlbumArtInfoBox.js
+++ b/src/content/dependencies/generateAlbumArtInfoBox.js
@@ -1,3 +1,7 @@
+import {basename} from 'node:path';
+
+import {empty} from '#sugar';
+
 export default {
   relations: (relation, album) => ({
     wallpaperArtistContributionsLine:
@@ -11,26 +15,100 @@ export default {
         ? relation('generateReleaseInfoContributionsLine',
             album.bannerArtwork.artistContribs)
         : null),
+
+    linkTemplate:
+      relation('linkTemplate'),
   }),
 
-  generate: (relations, {html, language}) =>
-    language.encapsulate('releaseInfo', capsule =>
-      html.tag('div', {class: 'album-art-info'},
-        {[html.onlyIfContent]: true},
-
-        html.tag('p',
-          {[html.onlyIfContent]: true},
-          {[html.joinChildren]: html.tag('br')},
-
-          [
-            relations.wallpaperArtistContributionsLine?.slots({
-              stringKey: capsule + '.wallpaperArtBy',
-              chronologyKind: 'wallpaperArt',
-            }),
-
-            relations.bannerArtistContributionsLine?.slots({
-              stringKey: capsule + '.bannerArtBy',
-              chronologyKind: 'bannerArt',
-            }),
-          ]))),
+  data: (album) => ({
+    wallpaperImagePath:
+      (album.wallpaperArtwork && empty(album.wallpaperParts)
+        ? album.wallpaperArtwork.path
+        : null),
+
+    wallpaperPartPaths:
+      album.wallpaperParts
+        .filter(part => part.asset)
+        .map(part => ['media.albumWallpaperPart', album.directory, part.asset]),
+
+    bannerImagePath:
+      (album.bannerArtwork
+        ? album.bannerArtwork.path
+        : null),
+  }),
+
+  generate: (data, relations, {html, language}) =>
+    html.tag('div', {class: 'album-art-info'},
+      {[html.onlyIfContent]: true},
+      {[html.joinChildren]: html.tag('hr', {class: 'cute'})},
+
+      [
+        language.encapsulate('releaseInfo', capsule =>
+          html.tag('p',
+            {[html.onlyIfContent]: true},
+            {[html.joinChildren]: html.tag('br')},
+
+            [
+              relations.wallpaperArtistContributionsLine?.slots({
+                stringKey: capsule + '.wallpaperArtBy',
+                chronologyKind: 'wallpaperArt',
+              }),
+
+              relations.bannerArtistContributionsLine?.slots({
+                stringKey: capsule + '.bannerArtBy',
+                chronologyKind: 'bannerArt',
+              }),
+            ])),
+
+        language.encapsulate('misc.downloadLayoutMedia', downloadCapsule =>
+          html.tag('p',
+            {[html.onlyIfContent]: true},
+            {[html.joinChildren]: html.tag('br')},
+
+            [
+              language.encapsulate(downloadCapsule, workingCapsule => {
+                const workingOptions = {};
+
+                let any = false;
+
+                if (data.wallpaperImagePath) {
+                  any = true;
+                  workingCapsule += '.withWallpaper';
+                  workingOptions.wallpaper =
+                    relations.linkTemplate.clone().slots({
+                      path: data.wallpaperImagePath,
+                      content: language.$(downloadCapsule, 'wallpaper'),
+                    });
+                }
+
+                if (data.bannerImagePath) {
+                  any = true;
+                  workingCapsule += '.withBanner';
+                  workingOptions.banner =
+                    relations.linkTemplate.clone().slots({
+                      path: data.bannerImagePath,
+                      content: language.$(downloadCapsule, 'banner'),
+                    });
+                }
+
+                if (any) {
+                  return language.$(workingCapsule, workingOptions);
+                } else {
+                  return html.blank();
+                }
+              }),
+
+              language.$(downloadCapsule, 'withWallpaperParts', {
+                [language.onlyIfOptions]: ['parts'],
+
+                parts:
+                  language.formatUnitList(
+                    data.wallpaperPartPaths.map(path =>
+                      relations.linkTemplate.clone().slots({
+                        path,
+                        content: language.sanitize(basename(path.at(-1))),
+                      }))),
+              }),
+            ])),
+      ]),
 };