diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 09:17:10 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:15 -0300 |
commit | e3533fb6db18cedb7b89d68221733a28595c65b4 (patch) | |
tree | 05c22ff75898a2b2dfd6574ba8cdd676db382fa7 /src/content/dependencies/generateExternalIcon.js | |
parent | b31764546474cff4e1b475587b3e4a2967473ce0 (diff) |
content: generateExternalIcon, extract from linkExternalAsIcon
Diffstat (limited to 'src/content/dependencies/generateExternalIcon.js')
-rw-r--r-- | src/content/dependencies/generateExternalIcon.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/content/dependencies/generateExternalIcon.js b/src/content/dependencies/generateExternalIcon.js new file mode 100644 index 00000000..cb65a00a --- /dev/null +++ b/src/content/dependencies/generateExternalIcon.js @@ -0,0 +1,28 @@ +import {isExternalLinkContext} from '#external-links'; + +export default { + extraDependencies: ['html', 'language', 'to'], + + data: (url) => ({url}), + + slots: { + context: { + // This awkward syntax is because the slot descriptor validator can't + // differentiate between a function that returns a validator (the usual + // syntax) and a function that is itself a validator. + validate: () => isExternalLinkContext, + default: 'generic', + }, + }, + + generate: (data, slots, {html, language, to}) => + html.tag('svg', + html.tag('use', { + href: + to('staticMisc.icon', + language.formatExternalLink(data.url, { + style: 'icon-id', + context: slots.context, + })), + })), +}; |