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
|
import {empty} from '#sugar';
export default {
slots: {
mode: {
validate: v => v.is('flash', 'album'),
},
id: {type: 'string'},
link: {
type: 'html',
mutable: false,
},
list: {
type: 'html',
mutable: false,
},
// Container and items, respectively.
date: {validate: v => v.isDate},
dates: {validate: v => v.sparseArrayOf(v.isDate)},
duration: {validate: v => v.isDuration},
durationApproximate: {type: 'boolean'},
},
generate(slots, {html, language}) {
let earliestItemDate = null;
let latestItemDate = null;
let onlyItemDate = null;
if (!empty(slots.dates)) {
earliestItemDate = slots.dates[0];
latestItemDate = slots.dates[1];
for (const date of slots.dates.slice(1)) {
if (date < earliestItemDate) earliestItemDate = date;
if (date > latestItemDate) latestItemDate = date;
}
if (+earliestItemDate === +latestItemDate) {
onlyItemDate = earliestItemDate;
}
}
let accentedLink;
switch (slots.mode) {
case 'album': {
const options = {album: slots.link};
const parts = ['artistPage.creditList.album'];
if (slots.date) {
parts.push('withDate');
options.date = language.formatDate(slots.date);
} else if (onlyItemDate) {
parts.push('withDate');
options.date = language.formatDate(onlyItemDate);
} else if (earliestItemDate && latestItemDate) {
parts.push('withDateRange');
options.dateRange =
language.formatDateRange(earliestItemDate, latestItemDate);
}
if (slots.duration) {
parts.push('withDuration');
options.duration =
language.formatDuration(slots.duration, {
approximate: slots.durationApproximate,
});
}
accentedLink = language.formatString(...parts, options);
break;
}
case 'flash': {
const options = {act: slots.link};
const parts = ['artistPage.creditList.flashAct'];
if (onlyItemDate) {
parts.push('withDate');
options.date = language.formatDate(onlyItemDate);
} else if (earliestItemDate && latestItemDate) {
parts.push('withDateRange');
options.dateRange =
language.formatDateRange(earliestItemDate, latestItemDate);
}
accentedLink = language.formatString(...parts, options);
break;
}
}
return html.tags([
html.tag('dt',
slots.id && {id: slots.id},
accentedLink),
html.tag('dd', slots.list),
]);
},
};
|