From 5408d6660b22b9ddee8c4a297c89fca92ae2d505 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 3 Jul 2023 23:12:03 -0300 Subject: content: listArtistsBy{CommentaryEntries,Name} + syntax changes --- .../dependencies/listArtistsByCommentaryEntries.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/content/dependencies/listArtistsByCommentaryEntries.js (limited to 'src/content/dependencies/listArtistsByCommentaryEntries.js') diff --git a/src/content/dependencies/listArtistsByCommentaryEntries.js b/src/content/dependencies/listArtistsByCommentaryEntries.js new file mode 100644 index 00000000..eae6dd6e --- /dev/null +++ b/src/content/dependencies/listArtistsByCommentaryEntries.js @@ -0,0 +1,55 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {filterByCount, 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 counts = + artists.map(artist => + artist.tracksAsCommentator.length + + artist.albumsAsCommentator.length); + + filterByCount(artists, counts); + sortByCount(artists, counts, {greatestFirst: true}); + + return {artists, counts, spec}; + }, + + relations(relation, query) { + return { + page: + relation('generateListingPage', query.spec), + + artistLinks: + query.artists + .map(artist => relation('linkArtist', artist)), + }; + }, + + data(query) { + return { + counts: query.counts, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.artistLinks, + count: data.counts, + }).map(({link, count}) => ({ + artist: link, + entries: language.countCommentaryEntries(count, {unit: true}), + })), + }); + }, +}; -- cgit 1.3.0-6-gf8a5