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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
import {stitchArrays} from '#sugar';
export default {
contentDependencies: [
'generateExternalHandle',
'generateExternalIcon',
'generateExternalPlatform',
],
extraDependencies: ['html', 'language'],
relations: (relation, contribution) => ({
icons:
contribution.artist.urls
.map(url => relation('generateExternalIcon', url)),
handles:
contribution.artist.urls
.map(url => relation('generateExternalHandle', url)),
platforms:
contribution.artist.urls
.map(url => relation('generateExternalPlatform', url)),
}),
data: (contribution) => ({
urls: contribution.artist.urls,
}),
generate: (data, relations, {html, language}) =>
language.encapsulate('misc.artistLink', capsule =>
html.tags(
stitchArrays({
icon: relations.icons,
handle: relations.handles,
platform: relations.platforms,
url: data.urls,
}).map(({icon, handle, platform, url}) => {
for (const template of [icon, handle, platform]) {
template.setSlot('context', 'artist');
}
return [
html.tag('a', {class: 'external-link'},
{href: url},
[
icon,
html.tag('span', {class: 'external-handle'},
(html.isBlank(handle)
? platform
: handle)),
]),
html.tag('span', {class: 'external-platform'},
// This is a pretty ridiculous hack, but we currently
// don't have a way of telling formatExternalLink to *not*
// use the fallback string, which just formats the URL as
// its host/domain... so is technically detectable.
(((new URL(url))
.host
.endsWith(
html.resolve(platform, {normalize: 'string'})))
? language.$(capsule, 'noExternalLinkPlatformName')
: platform)),
];
}))),
};
|