« get me outta code hell

content: generateContributionTooltip, etc - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateContributionTooltipExternalLinkSection.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-18 09:57:51 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:15 -0300
commit53b652508d83702f9451f0381d2f5a5ba76b7233 (patch)
tree3b557b211984090c8616df2cadefe5ed2029dcc5 /src/content/dependencies/generateContributionTooltipExternalLinkSection.js
parent6cbdcc8b041fc8e9a0300d9616ff5dafe0710c07 (diff)
content: generateContributionTooltip, etc
Diffstat (limited to 'src/content/dependencies/generateContributionTooltipExternalLinkSection.js')
-rw-r--r--src/content/dependencies/generateContributionTooltipExternalLinkSection.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/content/dependencies/generateContributionTooltipExternalLinkSection.js b/src/content/dependencies/generateContributionTooltipExternalLinkSection.js
new file mode 100644
index 00000000..3a124412
--- /dev/null
+++ b/src/content/dependencies/generateContributionTooltipExternalLinkSection.js
@@ -0,0 +1,48 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: ['linkExternalAsIcon'],
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, contribution) => ({
+    artistIcons:
+      contribution.artist.urls
+        .map(url => relation('linkExternalAsIcon', url)),
+  }),
+
+  data: (contribution) => ({
+    urls: contribution.artist.urls,
+  }),
+
+  generate: (data, relations, {html, language}) =>
+    language.encapsulate('misc.artistLink', capsule =>
+      stitchArrays({
+        icon: relations.artistIcons,
+        url: data.urls,
+      }).map(({icon, url}) => {
+          icon.setSlots({
+            context: 'artist',
+          });
+
+          let platformText =
+            language.formatExternalLink(url, {
+              context: 'artist',
+              style: 'platform',
+            });
+
+          // This is a pretty ridiculous hack, but we currently
+          // don't have a way of telling formatExternalLink to *not*
+          // use the fallback string, which just formats the URL as
+          // its host/domain... so is technically detectable.
+          if (platformText.toString() === (new URL(url)).host) {
+            platformText =
+              language.$(capsule, 'noExternalLinkPlatformName');
+          }
+
+          const platformSpan =
+            html.tag('span', {class: 'icon-platform'},
+              platformText);
+
+          return [icon, platformSpan];
+        })),
+};