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
|
import {sortAlbumsTracksChronologically, sortContributionsChronologically}
from '#sort';
import {chunkByConditions, stitchArrays} from '#sugar';
export default {
contentDependencies: [
'generateArtistInfoPageChunkedList',
'generateArtistInfoPageTracksChunk',
],
query(artist) {
const query = {};
const allContributions = [
...artist.artistContributions,
...artist.contributorContributions,
];
sortContributionsChronologically(
allContributions,
sortAlbumsTracksChronologically);
query.contribs =
// First chunk by (contribution) date and album.
chunkByConditions(allContributions, [
({date: date1}, {date: date2}) =>
+date1 !== +date2,
({thing: track1}, {thing: track2}) =>
track1.album !== track2.album,
]).map(contribs =>
// Then, *within* the boundaries of the existing chunks,
// chunk contributions to the same thing together.
chunkByConditions(contribs, [
({thing: thing1}, {thing: thing2}) =>
thing1 !== thing2,
]));
query.albums =
query.contribs
.map(contribs =>
contribs[0][0].thing.album);
return query;
},
relations: (relation, query, artist) => ({
chunkedList:
relation('generateArtistInfoPageChunkedList'),
chunks:
stitchArrays({
album: query.albums,
contribs: query.contribs,
}).map(({album, contribs}) =>
relation('generateArtistInfoPageTracksChunk',
artist,
album,
contribs)),
}),
generate: (relations) =>
relations.chunkedList.slots({
chunks: relations.chunks,
}),
};
|