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
|
import {compareArrays, empty} from '#sugar';
export default {
contentDependencies: [
'generateArtistCreditWikiEditsPart',
'linkContribution',
],
extraDependencies: ['html', 'language'],
query: (creditContributions, contextContributions) => {
const query = {};
const featuringFilter = contribution =>
contribution.annotation === 'featuring';
const wikiEditFilter = contribution =>
contribution.annotation?.startsWith('edits for wiki');
const normalFilter = contribution =>
!featuringFilter(contribution) &&
!wikiEditFilter(contribution);
query.normalContributions =
creditContributions.filter(normalFilter);
query.featuringContributions =
creditContributions.filter(featuringFilter);
query.wikiEditContributions =
creditContributions.filter(wikiEditFilter);
const contextNormalContributions =
contextContributions.filter(normalFilter);
query.normalContributionsAreDifferent =
!compareArrays(
query.normalContributions.map(({artist}) => artist),
contextNormalContributions.map(({artist}) => artist),
{checkOrder: false});
return query;
},
relations: (relation, query, _creditContributions, _contextContributions) => ({
normalContributionLinks:
query.normalContributions
.map(contrib => relation('linkContribution', contrib)),
featuringContributionLinks:
query.featuringContributions
.map(contrib => relation('linkContribution', contrib)),
wikiEditsPart:
relation('generateArtistCreditWikiEditsPart',
query.wikiEditContributions),
}),
data: (query, _creditContributions, _contextContributions) => ({
normalContributionsAreDifferent:
query.normalContributionsAreDifferent,
hasWikiEdits:
!empty(query.wikiEditContributions),
}),
slots: {
// This string is mandatory.
normalStringKey: {type: 'string'},
// This string is optional.
// Without it, there's no special behavior for "featuring" credits.
normalFeaturingStringKey: {type: 'string'},
// This string is optional.
// Without it, "featuring" credits will always be alongside main credits.
// It won't be used if contextContributions isn't provided.
featuringStringKey: {type: 'string'},
showAnnotation: {type: 'boolean', default: false},
showExternalLinks: {type: 'boolean', default: false},
showChronology: {type: 'boolean', default: false},
showWikiEdits: {type: 'boolean', default: false},
trimAnnotation: {type: 'boolean', default: false},
chronologyKind: {type: 'string'},
},
generate(data, relations, slots, {html, language}) {
if (!slots.normalStringKey) return html.blank();
for (const link of [
...relations.normalContributionLinks,
...relations.featuringContributionLinks,
]) {
link.setSlots({
showExternalLinks: slots.showExternalLinks,
showChronology: slots.showChronology,
trimAnnotation: slots.trimAnnotation,
chronologyKind: slots.chronologyKind,
});
}
for (const link of relations.normalContributionLinks) {
link.setSlots({
showAnnotation: slots.showAnnotation,
});
}
for (const link of relations.featuringContributionLinks) {
link.setSlots({
showAnnotation:
(slots.featuringStringKey
? false
: slots.showAnnotation),
});
}
if (empty(relations.normalContributionLinks)) {
return html.blank();
}
const artistsList =
(data.hasWikiEdits && slots.showWikiEdits
? language.$('misc.artistLink.withEditsForWiki', {
artists:
language.formatConjunctionList(relations.normalContributionLinks),
edits:
relations.wikiEditsPart.slots({
showAnnotation: slots.showAnnotation,
}),
})
: language.formatConjunctionList(relations.normalContributionLinks));
const featuringList =
language.formatConjunctionList(relations.featuringContributionLinks);
const everyoneList =
language.formatConjunctionList([
...relations.normalContributionLinks,
...relations.featuringContributionLinks,
]);
if (empty(relations.featuringContributionLinks)) {
if (data.normalContributionsAreDifferent) {
return language.$(slots.normalStringKey, {artists: artistsList});
} else {
return html.blank();
}
}
if (data.normalContributionsAreDifferent && slots.normalFeaturingStringKey) {
return language.$(slots.normalFeaturingStringKey, {
artists: artistsList,
featuring: featuringList,
});
} else if (slots.featuringStringKey) {
return language.$(slots.featuringStringKey, {artists: featuringList});
} else {
return language.$(slots.normalStringKey, {artists: everyoneList});
}
},
};
|