From a04652960a6d62ed74e1f9bd1a6157909d329bdf Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 7 Jul 2023 12:53:22 -0300 Subject: content: listGroupsBy{Albums,Tracks,Duration} --- src/content/dependencies/listGroupsByAlbums.js | 51 ++++++++++++++++++++++ src/content/dependencies/listGroupsByDuration.js | 55 ++++++++++++++++++++++++ src/content/dependencies/listGroupsByTracks.js | 55 ++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 src/content/dependencies/listGroupsByAlbums.js create mode 100644 src/content/dependencies/listGroupsByDuration.js create mode 100644 src/content/dependencies/listGroupsByTracks.js (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/listGroupsByAlbums.js b/src/content/dependencies/listGroupsByAlbums.js new file mode 100644 index 00000000..2235c0dd --- /dev/null +++ b/src/content/dependencies/listGroupsByAlbums.js @@ -0,0 +1,51 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {filterByCount, sortByCount} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkGroup'], + extraDependencies: ['language', 'wikiData'], + + sprawl({groupData}) { + return {groupData}; + }, + + query({groupData}, spec) { + const groups = groupData.slice(); + const counts = groups.map(group => group.albums.length); + + filterByCount(groups, counts); + sortByCount(groups, counts, {greatestFirst: true}); + + return {spec, groups, counts}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + groupLinks: + query.groups + .map(group => relation('linkGroup', group)), + }; + }, + + data(query) { + return { + counts: query.counts, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.groupLinks, + count: data.counts, + }).map(({link, count}) => ({ + group: link, + albums: language.countAlbums(count, {unit: true}), + })), + }); + }, +}; diff --git a/src/content/dependencies/listGroupsByDuration.js b/src/content/dependencies/listGroupsByDuration.js new file mode 100644 index 00000000..cf24a472 --- /dev/null +++ b/src/content/dependencies/listGroupsByDuration.js @@ -0,0 +1,55 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {filterByCount, getTotalDuration, sortByCount} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkGroup'], + extraDependencies: ['language', 'wikiData'], + + sprawl({groupData}) { + return {groupData}; + }, + + query({groupData}, spec) { + const groups = groupData.slice(); + const durations = + groups.map(group => + getTotalDuration( + group.albums.flatMap(album => album.tracks), + {originalReleasesOnly: true})); + + filterByCount(groups, durations); + sortByCount(groups, durations, {greatestFirst: true}); + + return {spec, groups, durations}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + groupLinks: + query.groups + .map(group => relation('linkGroup', group)), + }; + }, + + data(query) { + return { + durations: query.durations, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.groupLinks, + duration: data.durations, + }).map(({link, duration}) => ({ + group: link, + duration: language.formatDuration(duration), + })), + }); + }, +}; diff --git a/src/content/dependencies/listGroupsByTracks.js b/src/content/dependencies/listGroupsByTracks.js new file mode 100644 index 00000000..35ce153d --- /dev/null +++ b/src/content/dependencies/listGroupsByTracks.js @@ -0,0 +1,55 @@ +import {accumulateSum, stitchArrays} from '../../util/sugar.js'; +import {filterByCount, sortByCount} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkGroup'], + extraDependencies: ['language', 'wikiData'], + + sprawl({groupData}) { + return {groupData}; + }, + + query({groupData}, spec) { + const groups = groupData.slice(); + const counts = + groups.map(group => + accumulateSum( + group.albums, + ({tracks}) => tracks.length)); + + filterByCount(groups, counts); + sortByCount(groups, counts, {greatestFirst: true}); + + return {spec, groups, counts}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + groupLinks: + query.groups + .map(group => relation('linkGroup', group)), + }; + }, + + data(query) { + return { + counts: query.counts, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.groupLinks, + count: data.counts, + }).map(({link, count}) => ({ + group: link, + tracks: language.countTracks(count, {unit: true}), + })), + }); + }, +}; -- cgit 1.3.0-6-gf8a5