From 1d670edff0cdb6ff696cedac08ecbdf39aa7c085 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 2 Jul 2023 12:38:55 -0300 Subject: content: listAlbumsBy{Tracks,Duration,Date} --- src/content/dependencies/listAlbumsByDate.js | 52 +++++++++++++++++++++ src/content/dependencies/listAlbumsByDuration.js | 57 ++++++++++++++++++++++++ src/content/dependencies/listAlbumsByTracks.js | 53 ++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/content/dependencies/listAlbumsByDate.js create mode 100644 src/content/dependencies/listAlbumsByDuration.js create mode 100644 src/content/dependencies/listAlbumsByTracks.js (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/listAlbumsByDate.js b/src/content/dependencies/listAlbumsByDate.js new file mode 100644 index 00000000..1c584282 --- /dev/null +++ b/src/content/dependencies/listAlbumsByDate.js @@ -0,0 +1,52 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {sortChronologically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + return { + spec, + + albums: + sortChronologically(albumData.filter(album => album.date)), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + }; + }, + + data(query) { + return { + dates: + query.albums + .map(album => album.date), + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.albumLinks, + date: data.dates, + }).map(({link, date}) => ({ + album: link, + date: language.formatDate(date), + })), + }); + }, +}; diff --git a/src/content/dependencies/listAlbumsByDuration.js b/src/content/dependencies/listAlbumsByDuration.js new file mode 100644 index 00000000..e922ebc9 --- /dev/null +++ b/src/content/dependencies/listAlbumsByDuration.js @@ -0,0 +1,57 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {getTotalDuration} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + const albumToDuration = + new Map(albumData.map(album => [album, getTotalDuration(album.tracks)])); + + return { + spec, + + albums: + albumData + .filter(album => albumToDuration.get(album) > 0) + .sort((a, b) => albumToDuration.get(b) - albumToDuration.get(a)), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + }; + }, + + data(query) { + return { + durations: + query.albums + .map(album => getTotalDuration(album.tracks)), + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.albumLinks, + duration: data.durations, + }).map(({link, duration}) => ({ + album: link, + duration: language.formatDuration(duration), + })), + }); + }, +}; diff --git a/src/content/dependencies/listAlbumsByTracks.js b/src/content/dependencies/listAlbumsByTracks.js new file mode 100644 index 00000000..acec5da4 --- /dev/null +++ b/src/content/dependencies/listAlbumsByTracks.js @@ -0,0 +1,53 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + return { + spec, + + albums: + albumData + .filter(album => !empty(album.tracks)) + .sort((a, b) => b.tracks.length - a.tracks.length), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + }; + }, + + data(query) { + return { + counts: + query.albums + .map(album => album.tracks.length), + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.albumLinks, + count: data.counts, + }).map(({link, count}) => ({ + album: link, + tracks: language.countTracks(count, {unit: true}), + })), + }); + }, +}; -- cgit 1.3.0-6-gf8a5