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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
export default {
contentDependencies: ['linkArtist', 'linkExternal', 'transformContent'],
extraDependencies: ['html', 'language'],
relations: (relation, entry) => ({
content:
relation('transformContent', entry.body),
artistText:
relation('transformContent', entry.artistText),
artistLinks:
entry.artists
.filter(artist => artist.name !== 'HSMusic Wiki') // smh
.map(artist => relation('linkArtist', artist)),
sourceLinks:
entry.sourceURLs
.map(url => relation('linkExternal', url)),
originDetails:
relation('transformContent', entry.originDetails),
}),
data: (entry) => ({
isWikiLyrics:
entry.isWikiLyrics,
hasSquareBracketAnnotations:
entry.hasSquareBracketAnnotations,
numStanzas:
1 +
(Array.from(
entry.body
.matchAll(/\n\n|<br><br>/g))
.length) +
(entry.body.includes('<br')
? entry.body.split('\n').length
: 0),
numLines:
1 +
(Array.from(
entry.body
.replaceAll(/(<br>){1,}/g, '\n')
.replaceAll(/\n{2,}/g, '\n')
.matchAll(/\n/g))
.length),
}),
slots: {
attributes: {
type: 'attributes',
mutable: false,
},
},
generate: (data, relations, slots, {html, language}) =>
language.encapsulate('misc.lyrics', capsule =>
html.tag('div', {class: 'lyrics-entry'},
slots.attributes,
{'data-stanzas': data.numStanzas},
{'data-lines': data.numLines},
(data.numStanzas > 1 ||
data.numLines > 8) &&
{class: 'long-lyrics'},
[
html.tag('p', {class: 'lyrics-details'},
{[html.onlyIfContent]: true},
{[html.joinChildren]: html.tag('br')},
[
language.$(capsule, 'source', {
[language.onlyIfOptions]: ['source'],
source:
language.formatUnitList(
relations.sourceLinks.map(link =>
link.slots({
indicateExternal: true,
tab: 'separate',
}))),
}),
data.isWikiLyrics &&
language.$(capsule, 'contributors', {
[language.onlyIfOptions]: ['contributors'],
contributors:
(html.isBlank(relations.artistText)
? language.formatUnitList(relations.artistLinks)
: relations.artistText.slot('mode', 'inline')),
}),
// This check is doubled up only for clarity: entries are coded
// in data so that `hasSquareBracketAnnotations` is only true
// if `isWikiLyrics` is also true.
data.isWikiLyrics &&
data.hasSquareBracketAnnotations &&
language.$(capsule, 'squareBracketAnnotations'),
]),
html.tag('p', {class: 'origin-details'},
{[html.onlyIfContent]: true},
relations.originDetails.slots({
mode: 'inline',
absorbPunctuationFollowingExternalLinks: false,
})),
relations.content.slot('mode', 'lyrics'),
])),
};
|