From 882eb4325aa21d71fd8bbb466bb98bd9e22b4384 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 4 Jul 2023 10:02:54 -0300 Subject: content: listArtistsByDuration --- src/content/dependencies/listArtistsByDuration.js | 55 +++++++++++++++++++++++ src/listing-spec.js | 19 +------- 2 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 src/content/dependencies/listArtistsByDuration.js (limited to 'src') 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), + })), + }); + }, +}; diff --git a/src/listing-spec.js b/src/listing-spec.js index 1b0fe978..352f89db 100644 --- a/src/listing-spec.js +++ b/src/listing-spec.js @@ -77,24 +77,7 @@ listingSpec.push({ listingSpec.push({ directory: 'artists/by-duration', stringsKey: 'listArtists.byDuration', - - data: ({wikiData: {artistData}}) => - artistData - .map((artist) => ({ - artist, - duration: getTotalDuration([ - ...(artist.tracksAsArtist ?? []), - ...(artist.tracksAsContributor ?? []), - ], {originalReleasesOnly: true}), - })) - .filter(({duration}) => duration > 0) - .sort((a, b) => b.duration - a.duration), - - row: ({artist, duration}, {language, link}) => - language.$('listingPage.listArtists.byDuration.item', { - artist: link.artist(artist), - duration: language.formatDuration(duration), - }), + contentFunction: 'listArtistsByDuration', }); listingSpec.push({ -- cgit 1.3.0-6-gf8a5