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
|
import {unique} from '#sugar';
import {getTotalDuration} from '#wiki-data';
export default {
contentDependencies: [
'generateArtistInfoPageChunk',
'generateArtistInfoPageTracksChunkItem',
'linkAlbum',
],
relations: (relation, artist, album, trackContribLists) => ({
template:
relation('generateArtistInfoPageChunk'),
albumLink:
relation('linkAlbum', album),
// Intentional mapping here: each item may be associated with
// more than one contribution.
items:
trackContribLists.map(trackContribs =>
relation('generateArtistInfoPageTracksChunkItem',
artist,
trackContribs)),
}),
data(_artist, album, trackContribLists) {
const data = {};
const contribs =
trackContribLists.flat();
data.dates =
contribs
.map(contrib => contrib.date);
// TODO: Duration stuff should *maybe* be in proper data logic? Maaaybe?
const durationTerms =
unique(
contribs
.filter(contrib => contrib.countInDurationTotals)
.map(contrib => contrib.thing)
.filter(track => track.isOriginalRelease)
.filter(track => track.duration > 0));
data.duration =
getTotalDuration(durationTerms);
data.durationApproximate =
durationTerms.length > 1;
return data;
},
generate: (data, relations) =>
relations.template.slots({
mode: 'album',
albumLink: relations.albumLink,
dates: data.dates,
duration: data.duration,
durationApproximate: data.durationApproximate,
items: relations.items,
}),
};
|