diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-07-02 12:38:55 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-07-02 12:38:55 -0300 |
commit | 1d670edff0cdb6ff696cedac08ecbdf39aa7c085 (patch) | |
tree | 483afae9603441c823bab57ab243304b4a19c4fa /src/content | |
parent | 467bad1a645d77fc8b421ef9aeb9bbea6d2465ea (diff) |
content: listAlbumsBy{Tracks,Duration,Date}
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/dependencies/listAlbumsByDate.js | 52 | ||||
-rw-r--r-- | src/content/dependencies/listAlbumsByDuration.js | 57 | ||||
-rw-r--r-- | src/content/dependencies/listAlbumsByTracks.js | 53 |
3 files changed, 162 insertions, 0 deletions
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}), + })), + }); + }, +}; |