« get me outta code hell

data step: content function updates, relation syntax 2 - 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-19 16:26:55 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-19 16:26:55 -0300
commit41c22a553d43fbcc04b7a17ec6f83583ed7f3443 (patch)
tree88f8c25b84a586c31529ea95f96e51d2f6d78553 /src/content
parent7411fe87dc667b25f265f5388b790c5d4bbc880d (diff)
data step: content function updates, relation syntax 2
* new: generateAlbumTrackListItem
* new: generateContributionLinks
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateAlbumSocialEmbed.js8
-rw-r--r--src/content/dependencies/generateAlbumStylesheet.js2
-rw-r--r--src/content/dependencies/generateAlbumTrackListItem.js66
-rw-r--r--src/content/dependencies/generateContributionLinks.js80
4 files changed, 150 insertions, 6 deletions
diff --git a/src/content/dependencies/generateAlbumSocialEmbed.js b/src/content/dependencies/generateAlbumSocialEmbed.js
index b5c5ef66..87d8eed2 100644
--- a/src/content/dependencies/generateAlbumSocialEmbed.js
+++ b/src/content/dependencies/generateAlbumSocialEmbed.js
@@ -11,13 +11,11 @@ export default {
     'urls',
   ],
 
-  relations(album) {
+  relations(relation, album) {
     const relations = {};
 
-    relations.description = {
-      dependency: 'generateAlbumSocialEmbedDescription',
-      args: [album],
-    };
+    relations.description =
+      relation('generateAlbumSocialEmbedDescription', album);
 
     return relations;
   },
diff --git a/src/content/dependencies/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStylesheet.js
index 491a7be6..c9547836 100644
--- a/src/content/dependencies/generateAlbumStylesheet.js
+++ b/src/content/dependencies/generateAlbumStylesheet.js
@@ -5,7 +5,7 @@ export default {
     'to',
   ],
 
-  data: function(album) {
+  data(album) {
     const data = {};
 
     data.hasWallpaper = !empty(album.wallpaperArtistContribs);
diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js
new file mode 100644
index 00000000..fb315cb1
--- /dev/null
+++ b/src/content/dependencies/generateAlbumTrackListItem.js
@@ -0,0 +1,66 @@
+import {compareArrays} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'generateContributionLinks',
+    'linkTrack',
+  ],
+
+  extraDependencies: [
+    'getLinkThemeString',
+    'html',
+    'language',
+  ],
+
+  relations(relation, track) {
+    const relations = {};
+
+    relations.contributionLinks =
+      relation('generateContributionLinks', track.artistContribs, {
+        showContribution: false,
+        showIcons: false,
+      });
+
+    relations.trackLink =
+      relation('linkTrack', track);
+
+    return relations;
+  },
+
+  data(track) {
+    const data = {};
+
+    data.color = track.color;
+    data.duration = track.duration ?? 0;
+
+    data.showArtists =
+      !compareArrays(
+        track.artistContribs.map(c => c.who),
+        track.album.artistContribs.map(c => c.who),
+        {checkOrder: false});
+  },
+
+  generate(data, relations, {
+    getLinkThemeString,
+    html,
+    language,
+  }) {
+    const stringOpts = {
+      duration: language.formatDuration(data.duration),
+      track: relations.trackLink,
+    };
+
+    return html.tag('li',
+      {style: getLinkThemeString(data.color)},
+      (!data.showArtists
+        ? language.$('trackList.item.withDuration', stringOpts)
+        : language.$('trackList.item.withDuration.withArtists', {
+            ...stringOpts,
+            by:
+              html.tag('span', {class: 'by'},
+                language.$('trackList.item.withArtists.by', {
+                  artists: relations.contributionLinks,
+                })),
+          })));
+  },
+};
diff --git a/src/content/dependencies/generateContributionLinks.js b/src/content/dependencies/generateContributionLinks.js
new file mode 100644
index 00000000..74695796
--- /dev/null
+++ b/src/content/dependencies/generateContributionLinks.js
@@ -0,0 +1,80 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'linkArtist',
+  ],
+
+  relations(relation, contributions) {
+    const relations = {};
+
+    relations.artistLinks =
+      contributions.map(({who}) => relation('linkArtist', who));
+
+    return relations;
+  },
+
+  data(contributions, {
+    showContribution = false,
+    showIcons = false,
+  }) {
+    const data = {};
+
+    data.showContribution = showContribution;
+    data.showIcons = showIcons;
+
+    data.contributionData =
+      contributions.map(({who, what}) => ({
+        hasContributionPart: !!(showContribution && what),
+        hasExternalPart: !!(showIcons && !empty(who.urls)),
+        artistUrls: who.urls,
+        contribution: showContribution && what,
+      }));
+
+    return data;
+  },
+
+  generate(data, relations, {
+    html,
+    iconifyURL,
+    language,
+  }) {
+    return language.formatConjunctionList(
+      data.contributionData.map(({
+        hasContributionPart,
+        hasExternalPart,
+        artistUrls,
+        contribution,
+      }, index) => {
+        const artistLink = relations.artistLinks[index];
+
+        const externalLinks = hasExternalPart &&
+          html.tag('span',
+            {[html.noEdgeWhitespace]: true, class: 'icons'},
+            language.formatUnitList(
+              artistUrls.map(url => iconifyURL(url, {language}))));
+
+        return (
+          (hasContributionPart
+            ? (hasExternalPart
+                ? language.$('misc.artistLink.withContribution.withExternalLinks', {
+                    artist: artistLink,
+                    contrib: contribution,
+                    links: externalLinks,
+                  })
+                : language.$('misc.artistLink.withContribution', {
+                    artist: artistLink,
+                    contrib: contribution,
+                  }))
+            : (hasExternalPart
+                ? language.$('misc.artistLink.withExternalLinks', {
+                    artist: artistLink,
+                    links: externalLinks,
+                  })
+                : language.$('misc.artistLink', {
+                    artist: artistLink,
+                  })))
+        );
+      }));
+  },
+};