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 {sortChronologically} from '#sort';
import {accumulateSum, filterMultipleArrays, stitchArrays} from '#sugar';
export default {
contentDependencies: ['generatePageLayout', 'linkAlbumCommentary'],
extraDependencies: ['html', 'language', 'wikiData'],
sprawl({albumData}) {
return {albumData};
},
query(sprawl) {
const query = {};
query.albums =
sortChronologically(sprawl.albumData.slice());
const entries =
query.albums.map(album =>
[album, ...album.tracks]
.filter(({commentary}) => commentary)
.flatMap(({commentary}) => commentary));
query.wordCounts =
entries.map(entries =>
accumulateSum(
entries,
entry => entry.body.split(' ').length));
query.entryCounts =
entries.map(entries => entries.length);
filterMultipleArrays(query.albums, query.wordCounts, query.entryCounts,
(album, wordCount, entryCount) => entryCount >= 1);
return query;
},
relations(relation, query) {
return {
layout:
relation('generatePageLayout'),
albumLinks:
query.albums
.map(album => relation('linkAlbumCommentary', album)),
};
},
data(query) {
return {
wordCounts: query.wordCounts,
entryCounts: query.entryCounts,
totalWordCount: accumulateSum(query.wordCounts),
totalEntryCount: accumulateSum(query.entryCounts),
};
},
generate: (data, relations, {html, language}) =>
language.encapsulate('commentaryIndex', pageCapsule =>
relations.layout.slots({
title: language.$(pageCapsule, 'title'),
headingMode: 'static',
mainClasses: ['long-content'],
mainContent: [
html.tag('p', language.$(pageCapsule, 'infoLine', {
words:
html.tag('b',
language.formatWordCount(data.totalWordCount, {unit: true})),
entries:
html.tag('b',
language.countCommentaryEntries(data.totalEntryCount, {unit: true})),
})),
language.encapsulate(pageCapsule, 'albumList', listCapsule => [
html.tag('p',
language.$(listCapsule, 'title')),
html.tag('ul',
stitchArrays({
albumLink: relations.albumLinks,
wordCount: data.wordCounts,
entryCount: data.entryCounts,
}).map(({albumLink, wordCount, entryCount}) =>
html.tag('li',
language.$(listCapsule, 'item', {
album: albumLink,
words: language.formatWordCount(wordCount, {unit: true}),
entries: language.countCommentaryEntries(entryCount, {unit: true}),
})))),
]),
],
navLinkStyle: 'hierarchical',
navLinks: [
{auto: 'home'},
{auto: 'current'},
],
})),
};
|