diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-06-17 21:19:07 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:14 -0300 |
commit | 2ed49fea8ca5c49801e905bacce4c6aa96137867 (patch) | |
tree | 9b5f47a0852ee87b511fafb83d183a8b074a71fa /src/content/dependencies | |
parent | d2176d68113ed3bd409db35d2d2758b8e01bf6e3 (diff) |
content: linkContribution: refactor for multipart tooltip content
Diffstat (limited to 'src/content/dependencies')
-rw-r--r-- | src/content/dependencies/linkContribution.js | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/src/content/dependencies/linkContribution.js b/src/content/dependencies/linkContribution.js index 1a51c387..c17cc45a 100644 --- a/src/content/dependencies/linkContribution.js +++ b/src/content/dependencies/linkContribution.js @@ -50,15 +50,55 @@ export default { }, generate(data, relations, slots, {html, language}) { + const capsule = language.encapsulate('misc.artistLink'); + const hasContribution = !!(slots.showContribution && data.contribution); const hasExternalIcons = !!(slots.showIcons && relations.artistIcons); const parts = ['misc.artistLink']; const options = {}; + const tooltipContent = []; + + if (hasExternalIcons && slots.iconMode === 'tooltip') { + tooltipContent.push( + stitchArrays({ + icon: relations.artistIcons, + url: data.urls, + }).map(({icon, url}) => { + icon.setSlots({ + context: 'artist', + withText: true, + }); + + 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]; + })); + } + + // TODO: It probably shouldn't be necessary to do an isBlank call here. options.artist = - (hasExternalIcons && slots.iconMode === 'tooltip' - ? relations.textWithTooltip.slots({ + (html.isBlank(tooltipContent) + ? relations.artistLink + : relations.textWithTooltip.slots({ customInteractionCue: true, text: @@ -75,39 +115,9 @@ export default { {[html.joinChildren]: ''}, content: - stitchArrays({ - icon: relations.artistIcons, - url: data.urls, - }).map(({icon, url}) => { - icon.setSlots({ - context: 'artist', - withText: true, - }); - - 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.$('misc.artistLink.noExternalLinkPlatformName'); - } - - const platformSpan = - html.tag('span', {class: 'icon-platform'}, - platformText); - - return [icon, platformSpan]; - }), + tooltipContent, }), - }) - : relations.artistLink); + })); if (hasContribution) { parts.push('withContribution'); |