« get me outta code hell

linkExternalAsIcon.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/linkExternalAsIcon.js
blob: 58bd896d0639f68c1bbedb6e6c8a6bd466cf8c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export default {
  extraDependencies: ['html', 'language', 'to'],

  data: (url) => ({url}),

  slots: {
    withText: {type: 'boolean'},
  },

  generate(data, slots, {html, language, to}) {
    const {url} = data;

    const normalText = language.formatExternalLink(url, {style: 'normal'});
    const compactText = language.formatExternalLink(url, {style: 'compact'});
    const iconId = language.formatExternalLink(url, {style: 'icon-id'});

    return html.tag('a',
      {href: url, class: ['icon', slots.withText && 'has-text']},
      [
        html.tag('svg', [
          !slots.withText &&
            html.tag('title', normalText),

          html.tag('use', {
            href: to('shared.staticIcon', iconId),
          }),
        ]),

        slots.withText &&
          html.tag('span', {class: 'icon-text'},
            compactText ?? normalText),
      ]);
  },
};