« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/misc-templates.js75
-rw-r--r--src/page/album.js62
6 files changed, 150 insertions, 143 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,
+                  })))
+        );
+      }));
+  },
+};
diff --git a/src/misc-templates.js b/src/misc-templates.js
index e912c121..3e6948c0 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -18,10 +18,6 @@ import {
   sortChronologically,
 } from './util/wiki-data.js';
 
-import contentFunction from './util/content-function.js';
-
-import u_link from './util/link.js';
-
 const BANDCAMP_DOMAINS = ['bc.s3m.us', 'music.solatrux.com'];
 
 const MASTODON_DOMAINS = ['types.pl'];
@@ -80,77 +76,6 @@ function unbound_generateAdditionalFilesList(additionalFiles, {
     ]));
 }
 
-// Artist strings
-
-export const u_generateContributionLinks = contentFunction({
-  data: function(contributions, {
-    showContribution = false,
-    showIcons = false,
-  }) {
-    return {
-      showContribution,
-      showIcons,
-
-      contributionData:
-        contributions.map(({who, what}) => ({
-          artistLinkData: u_link.artist.data(who),
-
-          hasContributionPart: !!(showContribution && what),
-          hasExternalPart: !!(showIcons && !empty(who.urls)),
-
-          artistUrls: who.urls,
-          contribution: showContribution && what,
-        })),
-    };
-  },
-
-  generate: function generateContributionLinks(data, {
-    html,
-    iconifyURL,
-    language,
-    link,
-  }) {
-    return language.formatConjunctionList(
-      data.contributionData.map(({
-        artistLinkData,
-        hasContributionPart,
-        hasExternalPart,
-        artistUrls,
-        contribution,
-      }) => {
-        const artistLink = link.artist(artistLinkData);
-
-        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,
-                  })))
-        );
-      }));
-  },
-});
-
 // Chronology links
 
 function unbound_generateChronologyLinks(currentThing, {
diff --git a/src/page/album.js b/src/page/album.js
index 4cf9fd99..9e1d8c9f 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -150,68 +150,6 @@ export const dataSteps = {
   },
 };
 
-const u_generateTrackListItem = contentFunction({
-  contentDependencies: [
-    'generateContributionLinks',
-  ],
-
-  extraDependencies: [
-    'getLinkThemeString',
-    'html',
-    'language',
-    'link',
-  ],
-
-  data: function(track, {
-    generateContributionLinks,
-  }) {
-    return {
-      color: track.color,
-      duration: track.duration ?? 0,
-      linkData: u_link.track.data(track),
-
-      showArtists:
-        !compareArrays(
-          track.artistContribs.map(c => c.who),
-          track.album.artistContribs.map(c => c.who),
-          {checkOrder: false}),
-
-      contributionLinksData:
-        generateContributionLinks.data(track.artistContribs, {
-          showContribution: false,
-          showIcons: false,
-        }),
-    };
-  },
-
-  generate: function generateTrackListItem(data, {
-    generateContributionLinks,
-
-    getLinkThemeString,
-    html,
-    language,
-    link,
-  }) {
-    const stringOpts = {
-      duration: language.formatDuration(data.duration),
-      track: link.track(data.linkData),
-    };
-
-    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: generateContributionLinks(data.contributionLinksData),
-                })),
-          })));
-  },
-});
-
 /*
 const infoPage = {
   page: () => {