diff options
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/dependencies/listArtistsByDuration.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/content/dependencies/listArtistsByDuration.js b/src/content/dependencies/listArtistsByDuration.js new file mode 100644 index 00000000..478e99bb --- /dev/null +++ b/src/content/dependencies/listArtistsByDuration.js @@ -0,0 +1,55 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {filterByCount, getTotalDuration, sortByCount} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkArtist'], + extraDependencies: ['language', 'wikiData'], + + sprawl({artistData}) { + return {artistData}; + }, + + query({artistData}, spec) { + const artists = artistData.slice(); + const durations = artists.map(artist => + getTotalDuration([ + ...(artist.tracksAsArtist ?? []), + ...(artist.tracksAsContributor ?? []), + ], {originalReleasesOnly: true})); + + filterByCount(artists, durations); + sortByCount(artists, durations, {greatestFirst: true}); + + return {spec, artists, durations}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + artistLinks: + query.artists + .map(artist => relation('linkArtist', artist)), + }; + }, + + data(query) { + return { + durations: query.durations, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.artistLinks, + duration: data.durations, + }).map(({link, duration}) => ({ + artist: link, + duration: language.formatDuration(duration), + })), + }); + }, +}; |