From 68a062d92a07969ceb89075be979e1acdbeb679c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 29 Mar 2024 19:07:47 -0300 Subject: content: linkExternal: fall back to 'platform' style --- src/content/dependencies/linkExternal.js | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/content/dependencies/linkExternal.js b/src/content/dependencies/linkExternal.js index 282fb76c..f0947cb7 100644 --- a/src/content/dependencies/linkExternal.js +++ b/src/content/dependencies/linkExternal.js @@ -25,16 +25,32 @@ export default { }, }, - generate: (data, slots, {html, language}) => - html.tag('a', - {href: data.url}, - {class: 'nowrap'}, - - slots.tab === 'separate' && - {target: '_blank'}, - + generate(data, slots, {html, language}) { + let formattedText = language.formatExternalLink(data.url, { style: slots.style, context: slots.context, - })), + }); + + // Fall back to platform if nothing matched the desired style. + if (!formattedText && slots.style !== 'platform') { + formattedText = + language.formatExternalLink(data.url, { + style: 'platform', + context: slots.context, + }); + } + + const link = + html.tag('a', formattedText); + + link.attributes.set('href', data.url); + link.attributes.set('class', 'nowrap'); + + if (slots.tab === 'separate') { + link.attributes.set('target', '_blank'); + } + + return link; + }, }; -- cgit 1.3.0-6-gf8a5