« 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: 0217e9d6de73d120abcb69bf581ae4240bd84a71 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {isExternalLinkContext} from '#external-links';

export default {
  contentDependencies: [
    'generateExternalHandle',
    'generateExternalIcon',
    'generateExternalPlatform',
  ],

  extraDependencies: ['html'],

  relations: (relation, url) => ({
    icon:
      relation('generateExternalIcon', url),

    handle:
      relation('generateExternalHandle', url),

    platform:
      relation('generateExternalPlatform', url),
  }),

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

  slots: {
    context: {
      validate: () => isExternalLinkContext,
      default: 'generic',
    },
  },

  generate(data, relations, slots, {html}) {
    for (const template of [
      relations.icon,
      relations.handle,
      relations.platform,
    ]) {
      template.setSlot('context', slots.context);
    }

    return (
      html.tag('a', {class: 'icon'},
        {href: data.url},
        {class: 'has-text'},

        [
          relations.icon,

          html.tag('span', {class: 'icon-text'},
            (html.isBlank(relations.handle)
              ? relations.platform
              : relations.handle)),
        ]));
  },
};