diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-29 09:47:30 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-29 09:47:30 -0300 |
commit | 543d087fc465ea56ec0b156d488119c3a64c55aa (patch) | |
tree | 4298287941b09fe6c89731cf3222449f6d1a6c6f /src/content/dependencies/generateIconForURL.js | |
parent | f69d3397ea370793094261daa769aa893bdd74b1 (diff) |
content: iconifyURL (extra) -> generateIconForURL
Diffstat (limited to 'src/content/dependencies/generateIconForURL.js')
-rw-r--r-- | src/content/dependencies/generateIconForURL.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/content/dependencies/generateIconForURL.js b/src/content/dependencies/generateIconForURL.js new file mode 100644 index 00000000..4473ccbf --- /dev/null +++ b/src/content/dependencies/generateIconForURL.js @@ -0,0 +1,51 @@ +const BANDCAMP_DOMAINS = [ + 'bc.s3m.us', + 'music.solatrux.com', +]; + +const MASTODON_DOMAINS = [ + 'types.pl', +]; + +export default { + extraDependencies: ['html', 'language', 'to'], + + data(url) { + return {url}; + }, + + generate(data, {html, language, to}) { + const domain = new URL(data.url).hostname; + const [id, msg] = ( + domain.includes('bandcamp.com') + ? ['bandcamp', language.$('misc.external.bandcamp')] + : BANDCAMP_DOMAINS.includes(domain) + ? ['bandcamp', language.$('misc.external.bandcamp.domain', {domain})] + : MASTODON_DOMAINS.includes(domain) + ? ['mastodon', language.$('misc.external.mastodon.domain', {domain})] + : domain.includes('youtu') + ? ['youtube', language.$('misc.external.youtube')] + : domain.includes('soundcloud') + ? ['soundcloud', language.$('misc.external.soundcloud')] + : domain.includes('tumblr.com') + ? ['tumblr', language.$('misc.external.tumblr')] + : domain.includes('twitter.com') + ? ['twitter', language.$('misc.external.twitter')] + : domain.includes('deviantart.com') + ? ['deviantart', language.$('misc.external.deviantart')] + : domain.includes('instagram.com') + ? ['instagram', language.$('misc.external.bandcamp')] + : domain.includes('newgrounds.com') + ? ['newgrounds', language.$('misc.external.newgrounds')] + : ['globe', language.$('misc.external.domain', {domain})]); + + return html.tag('a', + {href: data.url, class: 'icon'}, + html.tag('svg', [ + html.tag('title', msg), + html.tag('use', { + href: to('shared.staticFile', `icons.svg#icon-${id}`), + }), + ])); + }, +}; |