1
1
import { sortAlphabetically } from '#sort' ;
2
- import { empty , filterMultipleArrays , stitchArrays , unique } from '#sugar' ;
3
- import { getArtistNumContributions } from '#wiki-data' ;
2
+ import {
3
+ empty ,
4
+ filterByCount ,
5
+ filterMultipleArrays ,
6
+ stitchArrays ,
7
+ transposeArrays ,
8
+ } from '#sugar' ;
4
9
5
10
export default {
6
11
contentDependencies : [ 'generateListingPage' , 'linkArtist' , 'linkGroup' ] ,
@@ -15,29 +20,52 @@ export default {
15
20
sortAlphabetically (
16
21
sprawl . artistData . filter ( artist => ! artist . isAlias ) ) ;
17
22
18
- const groups =
23
+ const interestingGroups =
19
24
sprawl . wikiInfo . divideTrackListsByGroups ;
20
25
21
- if ( empty ( groups ) ) {
22
- return { spec, artists } ;
26
+ if ( empty ( interestingGroups ) ) {
27
+ return { spec} ;
23
28
}
24
29
25
- const artistGroups =
30
+ // We don't actually care about *which* things belong to each group, only
31
+ // how many belong to each group. So we'll just compute a list of all the
32
+ // (interesting) groups that each of each artists' things belongs to.
33
+ const artistThingGroups =
26
34
artists . map ( artist =>
27
- unique (
28
- unique ( [
29
- ...artist . albumsAsAny ,
30
- ...artist . tracksAsAny . map ( track => track . album ) ,
31
- ] ) . flatMap ( album => album . groups ) ) )
32
-
33
- const artistsByGroup =
34
- groups . map ( group =>
35
- artists . filter ( ( artist , index ) => artistGroups [ index ] . includes ( group ) ) ) ;
36
-
37
- filterMultipleArrays ( groups , artistsByGroup ,
38
- ( group , artists ) => ! empty ( artists ) ) ;
39
-
40
- return { spec, groups, artistsByGroup} ;
35
+ ( [ ...artist . albumsAsAny . map ( album => album . groups ) ,
36
+ ...artist . tracksAsAny . map ( track => track . album . groups ) ] )
37
+ . map ( groups => groups
38
+ . filter ( group => interestingGroups . includes ( group ) ) ) ) ;
39
+
40
+ const [ artistsByGroup , countsByGroup ] =
41
+ transposeArrays ( interestingGroups . map ( group => {
42
+ const counts =
43
+ artistThingGroups
44
+ . map ( thingGroups => thingGroups
45
+ . filter ( thingGroups => thingGroups . includes ( group ) )
46
+ . length ) ;
47
+
48
+ const filteredArtists = artists . slice ( ) ;
49
+
50
+ filterByCount ( filteredArtists , counts ) ;
51
+
52
+ return [ filteredArtists , counts ] ;
53
+ } ) ) ;
54
+
55
+ const groups = interestingGroups ;
56
+
57
+ filterMultipleArrays (
58
+ groups ,
59
+ artistsByGroup ,
60
+ countsByGroup ,
61
+ ( _group , artists , _counts ) => ! empty ( artists ) ) ;
62
+
63
+ return {
64
+ spec,
65
+ groups,
66
+ artistsByGroup,
67
+ countsByGroup,
68
+ } ;
41
69
} ,
42
70
43
71
relations ( relation , query ) {
@@ -46,12 +74,6 @@ export default {
46
74
relations . page =
47
75
relation ( 'generateListingPage' , query . spec ) ;
48
76
49
- if ( query . artists ) {
50
- relations . artistLinks =
51
- query . artists
52
- . map ( artist => relation ( 'linkArtist' , artist ) ) ;
53
- }
54
-
55
77
if ( query . artistsByGroup ) {
56
78
relations . groupLinks =
57
79
query . groups
@@ -69,65 +91,43 @@ export default {
69
91
data ( query ) {
70
92
const data = { } ;
71
93
72
- if ( query . artists ) {
73
- data . counts =
74
- query . artists
75
- . map ( artist => getArtistNumContributions ( artist ) ) ;
76
- }
77
-
78
94
if ( query . artistsByGroup ) {
79
95
data . groupDirectories =
80
96
query . groups
81
97
. map ( group => group . directory ) ;
82
98
83
99
data . countsByGroup =
84
- query . artistsByGroup
85
- . map ( artists => artists
86
- . map ( artist => getArtistNumContributions ( artist ) ) ) ;
100
+ query . countsByGroup ;
87
101
}
88
102
89
103
return data ;
90
104
} ,
91
105
92
- generate ( data , relations , { language} ) {
93
- return (
94
- ( relations . artistLinksByGroup
95
- ? relations . page . slots ( {
96
- type : 'chunks' ,
97
-
98
- showSkipToSection : true ,
99
- chunkIDs :
100
- data . groupDirectories
101
- . map ( directory => `contributed-to-${ directory } ` ) ,
102
-
103
- chunkTitles :
104
- relations . groupLinks . map ( groupLink => ( {
105
- group : groupLink ,
106
- } ) ) ,
107
-
108
- chunkRows :
109
- stitchArrays ( {
110
- artistLinks : relations . artistLinksByGroup ,
111
- counts : data . countsByGroup ,
112
- } ) . map ( ( { artistLinks, counts} ) =>
113
- stitchArrays ( {
114
- link : artistLinks ,
115
- count : counts ,
116
- } ) . map ( ( { link, count} ) => ( {
117
- artist : link ,
118
- contributions : language . countContributions ( count , { unit : true } ) ,
119
- } ) ) ) ,
120
- } )
121
- : relations . page . slots ( {
122
- type : 'rows' ,
123
- rows :
124
- stitchArrays ( {
125
- link : relations . artistLinks ,
126
- count : data . counts ,
127
- } ) . map ( ( { link, count} ) => ( {
128
- artist : link ,
129
- contributions : language . countContributions ( count , { unit : true } ) ,
130
- } ) ) ,
131
- } ) ) ) ;
132
- } ,
106
+ generate : ( data , relations , { language} ) =>
107
+ relations . page . slots ( {
108
+ type : 'chunks' ,
109
+
110
+ showSkipToSection : true ,
111
+ chunkIDs :
112
+ data . groupDirectories
113
+ . map ( directory => `contributed-to-${ directory } ` ) ,
114
+
115
+ chunkTitles :
116
+ relations . groupLinks . map ( groupLink => ( {
117
+ group : groupLink ,
118
+ } ) ) ,
119
+
120
+ chunkRows :
121
+ stitchArrays ( {
122
+ artistLinks : relations . artistLinksByGroup ,
123
+ counts : data . countsByGroup ,
124
+ } ) . map ( ( { artistLinks, counts} ) =>
125
+ stitchArrays ( {
126
+ link : artistLinks ,
127
+ count : counts ,
128
+ } ) . map ( ( { link, count} ) => ( {
129
+ artist : link ,
130
+ contributions : language . countContributions ( count , { unit : true } ) ,
131
+ } ) ) ) ,
132
+ } ) ,
133
133
} ;
0 commit comments