From 53b652508d83702f9451f0381d2f5a5ba76b7233 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 18 Jun 2024 09:57:51 -0300 Subject: content: generateContributionTooltip, etc --- ...nerateContributionTooltipExternalLinkSection.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/content/dependencies/generateContributionTooltipExternalLinkSection.js (limited to 'src/content/dependencies/generateContributionTooltipExternalLinkSection.js') 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]; + })), +}; -- cgit 1.3.0-6-gf8a5