« get me outta code hell

data steps: content function evaluation essentials - 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:
author(quasar) nebula <qznebula@protonmail.com>2023-03-23 15:00:59 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-23 15:01:16 -0300
commit8ab00d99fa2f14ac983f0693552b26e4050a939c (patch)
tree1d75c569eec9472c95b24f5072d8d145bf709ee3 /src/content
parent95465bae3aaa92cb617c873bcbbfe8906bea7506 (diff)
data steps: content function evaluation essentials
Also some more actual content in generateAlbumInfoPageContent,
which is in fact fully working as-is(!!).
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateAdditionalFilesShortcut.js27
-rw-r--r--src/content/dependencies/generateAlbumInfoPageContent.js96
-rw-r--r--src/content/dependencies/linkAlbumAdditionalFile.js16
-rw-r--r--src/content/dependencies/linkAlbumCommentary.js8
-rw-r--r--src/content/dependencies/linkAlbumGallery.js8
-rw-r--r--src/content/dependencies/linkArtist.js11
-rw-r--r--src/content/dependencies/linkTemplate.js53
-rw-r--r--src/content/dependencies/linkThing.js51
8 files changed, 212 insertions, 58 deletions
diff --git a/src/content/dependencies/generateAdditionalFilesShortcut.js b/src/content/dependencies/generateAdditionalFilesShortcut.js
new file mode 100644
index 00000000..dd097e28
--- /dev/null
+++ b/src/content/dependencies/generateAdditionalFilesShortcut.js
@@ -0,0 +1,27 @@
+export default {
+  extraDependencies: [
+    'html',
+    'language',
+  ],
+
+  data(additionalFiles) {
+    return {
+      titles: additionalFiles.map(fileGroup => fileGroup.title),
+    };
+  },
+
+  generate(data, {
+    html,
+    language,
+  }) {
+    return language.$('releaseInfo.additionalFiles.shortcut', {
+      anchorLink:
+        html.tag('a',
+          {href: '#additional-files'},
+          language.$('releaseInfo.additionalFiles.shortcut.anchorLink')),
+
+      titles:
+        language.formatUnitList(data.titles),
+    });
+  },
+}
diff --git a/src/content/dependencies/generateAlbumInfoPageContent.js b/src/content/dependencies/generateAlbumInfoPageContent.js
index 013ab3f4..236e550e 100644
--- a/src/content/dependencies/generateAlbumInfoPageContent.js
+++ b/src/content/dependencies/generateAlbumInfoPageContent.js
@@ -2,9 +2,12 @@ import {accumulateSum, empty} from '../../util/sugar.js';
 
 export default {
   contentDependencies: [
+    'generateAdditionalFilesShortcut',
     'generateAlbumAdditionalFilesList',
     'generateContributionLinks',
     'generateContentHeading',
+    'linkAlbumCommentary',
+    'linkAlbumGallery',
   ],
 
   extraDependencies: [
@@ -18,9 +21,9 @@ export default {
 
     const contributionLinksRelation = contribs =>
       relation('generateContributionLinks', contribs, {
-        showContrib: true,
+        showContribution: true,
         showIcons: true,
-      })
+      });
 
     relations.artistLinks =
       contributionLinksRelation(album.artistContribs);
@@ -37,7 +40,20 @@ export default {
     const contentHeadingRelation = () =>
       relation('generateContentHeading');
 
+    if (album.tracks.some(t => t.hasUniqueCoverArt)) {
+      relations.galleryLink =
+        relation('linkAlbumGallery', album);
+    }
+
+    if (album.commentary || album.tracks.some(t => t.commentary)) {
+      relations.commentaryLink =
+        relation('linkAlbumCommentary', album);
+    }
+
     if (!empty(album.additionalFiles)) {
+      relations.additionalFilesShortcut =
+        relation('generateAdditionalFilesShortcut', album.additionalFiles);
+
       relations.additionalFilesHeading =
         contentHeadingRelation();
 
@@ -84,29 +100,29 @@ export default {
 
     content.main = {
       headingMode: 'sticky',
-      content: [
+      content: html.tag(null, [
         html.tag('p',
           {
             [html.onlyIfContent]: true,
             [html.joinChildren]: '<br>',
           },
           [
-            !empty(relations.artistLinks) &&
+            relations.artistLinks &&
               language.$('releaseInfo.by', {
                 artists: relations.artistLinks,
               }),
 
-            !empty(relations.coverArtistLinks) &&
+            relations.coverArtistLinks &&
               language.$('releaseInfo.coverArtBy', {
                 artists: relations.coverArtistLinks,
               }),
 
-            !empty(relations.wallpaperArtistLinks) &&
+            relations.wallpaperArtistLinks &&
               language.$('releaseInfo.wallpaperArtBy', {
                 artists: relations.wallpaperArtistLinks,
               }),
 
-            !empty(relations.bannerArtistLinks) &&
+            relations.bannerArtistLinks &&
               language.$('releaseInfo.bannerArtBy', {
                 artists: relations.bannerArtistLinks,
               }),
@@ -130,31 +146,30 @@ export default {
               }),
           ]),
 
-        /*
-          html.tag('p',
-            {
-              [html.onlyIfContent]: true,
-              [html.joinChildren]: '<br>',
-            },
-            [
-              hasAdditionalFiles &&
-                generateAdditionalFilesShortcut(album.additionalFiles),
+        html.tag('p',
+          {
+            [html.onlyIfContent]: true,
+            [html.joinChildren]: html.tag('br'),
+          },
+          [
+            relations.additionalFilesShortcut,
 
-              checkGalleryPage(album) &&
-                language.$('releaseInfo.viewGallery', {
-                  link: link.albumGallery(album, {
-                    text: language.$('releaseInfo.viewGallery.link'),
-                  }),
-                }),
+            relations.galleryLink &&
+              language.$('releaseInfo.viewGallery', {
+                link:
+                  relations.galleryLink
+                    .slot('text', language.$('releaseInfo.viewGallery.link')),
+              }),
 
-              checkCommentaryPage(album) &&
-                language.$('releaseInfo.viewCommentary', {
-                  link: link.albumCommentary(album, {
-                    text: language.$('releaseInfo.viewCommentary.link'),
-                  }),
-                }),
-            ]),
+            relations.commentaryLink &&
+              language.$('releaseInfo.viewCommentary', {
+                link:
+                  relations.commentaryLink
+                    .slot('text', language.$('releaseInfo.viewCommentary.link')),
+              }),
+          ]),
 
+        /*
           !empty(album.urls) &&
             html.tag('p',
               language.$('releaseInfo.listenOn', {
@@ -204,25 +219,6 @@ export default {
                   ),
                 })
             ]),
-
-          ...html.fragment(
-            hasAdditionalFiles && [
-              generateContentHeading({
-                id: 'additional-files',
-                title: language.$('releaseInfo.additionalFiles.heading', {
-                  additionalFiles: language.countAdditionalFiles(numAdditionalFiles, {
-                    unit: true,
-                  }),
-                }),
-              }),
-
-              generateAlbumAdditionalFilesList(album, album.additionalFiles, {
-                generateAdditionalFilesList,
-                getSizeOfAdditionalFile,
-                link,
-                urls,
-              }),
-            ]),
         */
 
         relations.additionalFilesList && [
@@ -240,12 +236,12 @@ export default {
         data.artistCommentary && [
           relations.artistCommentaryHeading
             .slot('id', 'artist-commentary')
-            .slot('title', language.$('releaseDate.artistCommentary')),
+            .slot('title', language.$('releaseInfo.artistCommentary')),
 
           html.tag('blockquote',
             transformMultiline(data.artistCommentary)),
         ],
-      ]
+      ]),
     };
 
     return content;
diff --git a/src/content/dependencies/linkAlbumAdditionalFile.js b/src/content/dependencies/linkAlbumAdditionalFile.js
index 6c47edca..d1cca914 100644
--- a/src/content/dependencies/linkAlbumAdditionalFile.js
+++ b/src/content/dependencies/linkAlbumAdditionalFile.js
@@ -1,4 +1,14 @@
 export default {
+  contentDependencies: [
+    'linkTemplate',
+  ],
+
+  relations(relation) {
+    return {
+      linkTemplate: relation('linkTemplate'),
+    };
+  },
+
   data(album, file) {
     return {
       albumDirectory: album.directory,
@@ -6,7 +16,9 @@ export default {
     };
   },
 
-  generate(data) {
-    return `(stub album additional file link: ${data.albumDirectory}/${data.file})`;
+  generate(data, relations) {
+    return relations.linkTemplate
+      .slot('path', ['media.albumAdditionalFile', data.albumDirectory, data.file])
+      .slot('content', data.file);
   },
 };
diff --git a/src/content/dependencies/linkAlbumCommentary.js b/src/content/dependencies/linkAlbumCommentary.js
new file mode 100644
index 00000000..ab519fd6
--- /dev/null
+++ b/src/content/dependencies/linkAlbumCommentary.js
@@ -0,0 +1,8 @@
+export default {
+  contentDependencies: ['linkThing'],
+
+  relations: (relation, album) =>
+    ({link: relation('linkThing', 'localized.albumCommentary', album)}),
+
+  generate: (relations) => relations.link,
+};
diff --git a/src/content/dependencies/linkAlbumGallery.js b/src/content/dependencies/linkAlbumGallery.js
new file mode 100644
index 00000000..e3f30a29
--- /dev/null
+++ b/src/content/dependencies/linkAlbumGallery.js
@@ -0,0 +1,8 @@
+export default {
+  contentDependencies: ['linkThing'],
+
+  relations: (relation, album) =>
+    ({link: relation('linkThing', 'localized.albumGallery', album)}),
+
+  generate: (relations) => relations.link,
+};
diff --git a/src/content/dependencies/linkArtist.js b/src/content/dependencies/linkArtist.js
index 396eca41..718ee6fa 100644
--- a/src/content/dependencies/linkArtist.js
+++ b/src/content/dependencies/linkArtist.js
@@ -1,9 +1,8 @@
 export default {
-  data(artist) {
-    return {directory: artist.directory};
-  },
+  contentDependencies: ['linkThing'],
 
-  generate(data) {
-    return `(stub artist link: "${data.directory}")`;
-  },
+  relations: (relation, artist) =>
+    ({link: relation('linkThing', 'localized.artist', artist)}),
+
+  generate: (relations) => relations.link,
 };
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js
new file mode 100644
index 00000000..94b90652
--- /dev/null
+++ b/src/content/dependencies/linkTemplate.js
@@ -0,0 +1,53 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  extraDependencies: [
+    'appendIndexHTML',
+    'getColors',
+    'html',
+    'to',
+  ],
+
+  generate({
+    appendIndexHTML,
+    getColors,
+    html,
+    to,
+  }) {
+    return html.template(slot =>
+      slot('color', ([color]) =>
+      slot('hash', ([hash]) =>
+      slot('href', ([href]) =>
+      slot('path', ([...path]) => {
+        let style;
+
+        if (!href && !empty(path)) {
+          href = to(...path);
+        }
+
+        if (appendIndexHTML) {
+          if (/^(?!https?:\/\/).+\/$/.test(href)) {
+            href += 'index.html';
+          }
+        }
+
+        if (hash) {
+          href += (hash.startsWith('#') ? '' : '#') + hash;
+        }
+
+        if (color) {
+          const {primary, dim} = getColors(color);
+          style = `--primary-color: ${primary}; --dim-color: ${dim}`;
+        }
+
+        return slot('attributes', ([attributes]) =>
+          html.tag('a',
+            {
+              ...attributes ?? {},
+              href,
+              style,
+            },
+            slot('content')));
+      })))));
+  },
+}
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
new file mode 100644
index 00000000..ebff6761
--- /dev/null
+++ b/src/content/dependencies/linkThing.js
@@ -0,0 +1,51 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'linkTemplate',
+  ],
+
+  extraDependencies: [
+    'html',
+  ],
+
+  relations(relation) {
+    return {
+      linkTemplate: relation('linkTemplate'),
+    };
+  },
+
+  data(pathKey, thing) {
+    return {
+      pathKey,
+
+      color: thing.color,
+      directory: thing.directory,
+
+      name: thing.name,
+      nameShort: thing.nameShort,
+    };
+  },
+
+  generate(data, relations, {html}) {
+    const path = [data.pathKey, data.directory];
+
+    return html.template(slot =>
+      slot('content', ([...content]) =>
+      slot('preferShortName', ([preferShortName]) => {
+        if (empty(content)) {
+          content =
+            (preferShortName
+              ? data.nameShort ?? data.name
+              : data.name);
+        }
+
+        return relations.linkTemplate
+          .slot('path', path)
+          .slot('color', slot('color', data.color))
+          .slot('attributes', slot('attributes', {}))
+          .slot('hash', slot('hash'))
+          .slot('content', content);
+      })));
+  },
+}