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
|
import {empty} from '#sugar';
export default {
extraDependencies: ['html', 'language'],
slots: {
mode: {
validate: v => v.is('flash', 'album'),
},
albumLink: {
type: 'html',
mutable: false,
},
flashActLink: {
type: 'html',
mutable: false,
},
items: {
type: 'html',
mutable: false,
},
dates: {
validate: v => v.sparseArrayOf(v.isDate),
},
duration: {validate: v => v.isDuration},
durationApproximate: {type: 'boolean'},
trimAnnotations: {
type: 'boolean',
default: false,
},
},
generate(slots, {html, language}) {
let earliestDate = null;
let latestDate = null;
let onlyDate = null;
if (!empty(slots.dates)) {
earliestDate =
slots.dates
.reduce((a, b) => a <= b ? a : b);
latestDate =
slots.dates
.reduce((a, b) => a <= b ? b : a);
if (+earliestDate === +latestDate) {
onlyDate = earliestDate;
}
}
let accentedLink;
accent: {
switch (slots.mode) {
case 'album': {
accentedLink = slots.albumLink;
const options = {album: accentedLink};
const parts = ['artistPage.creditList.album'];
if (onlyDate) {
parts.push('withDate');
options.date = language.formatDate(onlyDate);
}
if (slots.duration) {
parts.push('withDuration');
options.duration =
language.formatDuration(slots.duration, {
approximate: slots.durationApproximate,
});
}
accentedLink = language.formatString(...parts, options);
break;
}
case 'flash': {
accentedLink = slots.flashActLink;
const options = {act: accentedLink};
const parts = ['artistPage.creditList.flashAct'];
if (onlyDate) {
parts.push('withDate');
options.date = language.formatDate(onlyDate);
} else if (earliestDate && latestDate) {
parts.push('withDateRange');
options.dateRange =
language.formatDateRange(earliestDate, latestDate);
}
accentedLink = language.formatString(...parts, options);
break;
}
}
}
return html.tags([
html.tag('dt', accentedLink),
html.tag('dd',
html.tag('ul',
slots.items
.map(item => item.slots({
trimAnnotation: slots.trimAnnotations,
})))),
]);
},
};
|