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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
import {sortAlbumsTracksChronologically} from '#sort';
import {empty, unique} from '#sugar';
import {getTotalDuration} from '#wiki-data';
function countTowardTrackTotals(contribs) {
const {thing} = contribs[0];
const track = thing.isTrack ? thing : null;
if (!track) return null;
// For secondary releases the goal is to check if the corresponding
// contribution on the main release would be counted toward track totals.
// If any of the artist's contributions on the secondary release don't
// apparently correspond to any on the main release, those will just
// get checked themselves.
if (track.isSecondaryRelease) {
const relevantProperties =
unique(contribs.map(contrib => contrib.thingProperty));
const arrays =
Object.fromEntries(
relevantProperties.map(prop => [
prop,
track.mainReleaseTrack[prop].slice(),
]));
contribs = contribs.map(a => {
const array = arrays[a.thingProperty];
const index =
array.findIndex(b =>
b.artist === a.artist &&
b.annotation === a.annotation);
if (index >= 0) {
return array.splice(index, 1).at(0);
} else {
return a;
}
});
}
return contribs.some(contrib =>
contrib.countInContributionTotals ||
contrib.countInDurationTotals);
}
export default {
query: (_artist, _album, trackContribLists) => ({
isAlbumArtist:
trackContribLists.flat()
.some(contrib =>
contrib.thingProperty === 'artistContribs' &&
contrib.thing.isAlbum),
contribListsCountingTowardTotals:
trackContribLists
.filter(contribs => countTowardTrackTotals(contribs) === true),
contribListsNotCountingTowardTotals:
trackContribLists
.filter(contribs => countTowardTrackTotals(contribs) === false),
}),
relations: (relation, query, artist, album, _trackContribLists) => ({
template:
relation('generateArtistInfoPageChunk'),
albumLink:
relation('linkAlbum', album),
albumArtistCredit:
relation('generateArtistCredit', album.artistContribs, []),
albumArtistOnlyItem:
(query.isAlbumArtist &&
empty(query.contribListsCountingTowardTotals) &&
empty(query.contribListsNotCountingTowardTotals)
? relation('generateArtistInfoPageAlbumArtistOnlyChunkItem')
: null),
itemsCountingTowardTotals:
query.contribListsCountingTowardTotals.map(trackContribs =>
relation('generateArtistInfoPageTracksChunkItem',
artist,
trackContribs)),
itemsNotCountingTowardTotals:
query.contribListsNotCountingTowardTotals.map(trackContribs =>
relation('generateArtistInfoPageTracksChunkItem',
artist,
trackContribs)),
}),
data(artist, _query, 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.isMainRelease)
.filter(track => track.duration > 0));
data.duration =
getTotalDuration(durationTerms);
data.durationApproximate =
durationTerms.length > 1;
const tracks =
trackContribLists
.map(contribs => contribs[0].thing)
.filter(thing => thing.isTrack);
data.numLinkingOtherReleases =
tracks.filter(track => {
if (empty(track.otherReleases)) return false;
const releases =
sortAlbumsTracksChronologically(track.allReleases.slice());
// later releases always link to first release
if (track !== releases[0]) return true;
// first releases only link to later credited releases
return tracks.slice(1).some(track => {
const contribs = [
...track.artistContribs,
...track.contributorContribs,
];
return contribs.some(contrib => contrib.artist === artist);
});
}).length;
return data;
},
generate: (data, relations, {html, language}) =>
relations.template.slots({
mode: 'album',
link:
language.encapsulate('artistPage.creditList.album', workingCapsule => {
const creditCapsule = workingCapsule + '.credit';
const workingOptions = {album: relations.albumLink};
relations.albumArtistCredit.setSlots({
normalStringKey: creditCapsule + '.by',
});
if (!html.isBlank(relations.albumArtistCredit)) {
workingCapsule += '.withCredit';
workingOptions.credit =
html.tag('span', {class: 'by'},
relations.albumArtistCredit);
}
return language.$(workingCapsule, workingOptions);
}),
dates: data.dates,
duration: data.duration,
durationApproximate: data.durationApproximate,
list:
html.tag('ul',
data.numLinkingOtherReleases > 1 &&
{class: 'offset-tooltips'},
[
relations.albumArtistOnlyItem,
relations.itemsCountingTowardTotals,
!empty(relations.itemsCountingTowardTotals) &&
!empty(relations.itemsNotCountingTowardTotals) &&
html.tag('li', {class: 'divider'},
html.tag('hr')),
relations.itemsNotCountingTowardTotals
.map(item => item.slot('showDuration', false)),
]),
}),
};
|