From 4cbde0e670e5812254509f1f5da39241304dacc0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 27 Jul 2023 16:32:37 -0300 Subject: content: track listings --- src/content/dependencies/listTracksByAlbum.js | 48 +++++++++++ src/content/dependencies/listTracksByDate.js | 82 +++++++++++++++++++ src/content/dependencies/listTracksByDuration.js | 51 ++++++++++++ .../dependencies/listTracksByDurationInAlbum.js | 93 ++++++++++++++++++++++ src/content/dependencies/listTracksByName.js | 36 +++++++++ .../dependencies/listTracksByTimesReferenced.js | 57 +++++++++++++ .../dependencies/listTracksInFlashesByAlbum.js | 82 +++++++++++++++++++ .../dependencies/listTracksInFlashesByFlash.js | 69 ++++++++++++++++ src/content/dependencies/listTracksWithExtra.js | 81 +++++++++++++++++++ src/content/dependencies/listTracksWithLyrics.js | 9 +++ .../dependencies/listTracksWithMidiProjectFiles.js | 9 +++ .../dependencies/listTracksWithSheetMusicFiles.js | 9 +++ 12 files changed, 626 insertions(+) create mode 100644 src/content/dependencies/listTracksByAlbum.js create mode 100644 src/content/dependencies/listTracksByDate.js create mode 100644 src/content/dependencies/listTracksByDuration.js create mode 100644 src/content/dependencies/listTracksByDurationInAlbum.js create mode 100644 src/content/dependencies/listTracksByName.js create mode 100644 src/content/dependencies/listTracksByTimesReferenced.js create mode 100644 src/content/dependencies/listTracksInFlashesByAlbum.js create mode 100644 src/content/dependencies/listTracksInFlashesByFlash.js create mode 100644 src/content/dependencies/listTracksWithExtra.js create mode 100644 src/content/dependencies/listTracksWithLyrics.js create mode 100644 src/content/dependencies/listTracksWithMidiProjectFiles.js create mode 100644 src/content/dependencies/listTracksWithSheetMusicFiles.js (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/listTracksByAlbum.js b/src/content/dependencies/listTracksByAlbum.js new file mode 100644 index 00000000..b2405034 --- /dev/null +++ b/src/content/dependencies/listTracksByAlbum.js @@ -0,0 +1,48 @@ +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + return { + spec, + albums: albumData, + tracks: albumData.map(album => album.tracks), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + + trackLinks: + query.tracks + .map(tracks => tracks + .map(track => relation('linkTrack', track))), + }; + }, + + generate(relations) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + relations.albumLinks + .map(albumLink => ({album: albumLink})), + + listStyle: 'ordered', + + chunkRows: + relations.trackLinks + .map(trackLinks => trackLinks + .map(trackLink => ({track: trackLink}))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksByDate.js b/src/content/dependencies/listTracksByDate.js new file mode 100644 index 00000000..25039c3e --- /dev/null +++ b/src/content/dependencies/listTracksByDate.js @@ -0,0 +1,82 @@ +import {stitchArrays} from '../../util/sugar.js'; + +import { + chunkByProperties, + sortAlbumsTracksChronologically, +} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({trackData}) { + return {trackData}; + }, + + query({trackData}, spec) { + return { + spec, + + chunks: + chunkByProperties( + sortAlbumsTracksChronologically(trackData.slice()), + ['album', 'date']), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.chunks + .map(({album}) => relation('linkAlbum', album)), + + trackLinks: + query.chunks + .map(({chunk}) => chunk + .map(track => relation('linkTrack', track))), + }; + }, + + data(query) { + return { + dates: + query.chunks + .map(({date}) => date), + + rereleases: + query.chunks.map(({chunk}) => + chunk.map(track => + track.originalReleaseTrack !== null)), + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + stitchArrays({ + albumLink: relations.albumLinks, + date: data.dates, + }).map(({albumLink, date}) => ({ + album: albumLink, + date: language.formatDate(date), + })), + + chunkRows: + stitchArrays({ + trackLinks: relations.trackLinks, + rereleases: data.rereleases, + }).map(({trackLinks, rereleases}) => + stitchArrays({ + trackLink: trackLinks, + rerelease: rereleases, + }).map(({trackLink, rerelease}) => + (rerelease + ? {track: trackLink, stringsKey: 'rerelease'} + : {track: trackLink}))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksByDuration.js b/src/content/dependencies/listTracksByDuration.js new file mode 100644 index 00000000..329ada5b --- /dev/null +++ b/src/content/dependencies/listTracksByDuration.js @@ -0,0 +1,51 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {filterByCount, sortAlphabetically, sortByCount} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({trackData}) { + return {trackData}; + }, + + query({trackData}, spec) { + const tracks = sortAlphabetically(trackData.slice()); + const durations = tracks.map(track => track.duration); + + filterByCount(tracks, durations); + sortByCount(tracks, durations, {greatestFirst: true}); + + return {spec, tracks, durations}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + trackLinks: + query.tracks + .map(track => relation('linkTrack', track)), + }; + }, + + data(query) { + return { + durations: query.durations, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.trackLinks, + duration: data.durations, + }).map(({link, duration}) => ({ + track: link, + duration: language.formatDuration(duration), + })), + }); + }, +}; diff --git a/src/content/dependencies/listTracksByDurationInAlbum.js b/src/content/dependencies/listTracksByDurationInAlbum.js new file mode 100644 index 00000000..b5a80a71 --- /dev/null +++ b/src/content/dependencies/listTracksByDurationInAlbum.js @@ -0,0 +1,93 @@ +import {stitchArrays} from '../../util/sugar.js'; + +import { + filterByCount, + filterMultipleArrays, + sortByCount, + sortChronologically, +} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + const albums = sortChronologically(albumData.slice()); + + const tracks = + albums.map(album => + album.tracks.slice()); + + const durations = + tracks.map(tracks => + tracks.map(track => + track.duration)); + + // Filter out tracks without any duration. + // Sort at the same time, to avoid redundantly stitching again later. + const stitched = stitchArrays({tracks, durations}); + for (const {tracks, durations} of stitched) { + filterByCount(tracks, durations); + sortByCount(tracks, durations, {greatestFirst: true}); + } + + // Filter out albums which don't have at least two (remaining) tracks. + // If the album only has one track in the first place, or if only one + // has any duration, then there aren't any comparisons to be made and + // it just takes up space on the listing page. + const numTracks = tracks.map(tracks => tracks.length); + filterMultipleArrays(albums, tracks, durations, numTracks, + (album, tracks, durations, numTracks) => + numTracks >= 2); + + return {spec, albums, tracks, durations}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + + trackLinks: + query.tracks + .map(tracks => tracks + .map(track => relation('linkTrack', track))), + }; + }, + + data(query) { + return { + durations: query.durations, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + relations.albumLinks + .map(albumLink => ({album: albumLink})), + + chunkRows: + stitchArrays({ + trackLinks: relations.trackLinks, + durations: data.durations, + }).map(({trackLinks, durations}) => + stitchArrays({ + trackLink: trackLinks, + duration: durations, + }).map(({trackLink, duration}) => ({ + track: trackLink, + duration: language.formatDuration(duration), + }))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksByName.js b/src/content/dependencies/listTracksByName.js new file mode 100644 index 00000000..dd989e98 --- /dev/null +++ b/src/content/dependencies/listTracksByName.js @@ -0,0 +1,36 @@ +import {sortAlphabetically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkTrack'], + extraDependencies: ['wikiData'], + + sprawl({trackData}) { + return {trackData}; + }, + + query({trackData}, spec) { + return { + spec, + tracks: sortAlphabetically(trackData.slice()), + }; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + trackLinks: + query.tracks + .map(track => relation('linkTrack', track)), + }; + }, + + generate(relations) { + return relations.page.slots({ + type: 'rows', + rows: + relations.trackLinks + .map(link => ({track: link})), + }); + }, +}; diff --git a/src/content/dependencies/listTracksByTimesReferenced.js b/src/content/dependencies/listTracksByTimesReferenced.js new file mode 100644 index 00000000..64d762df --- /dev/null +++ b/src/content/dependencies/listTracksByTimesReferenced.js @@ -0,0 +1,57 @@ +import {stitchArrays} from '../../util/sugar.js'; + +import { + filterByCount, + sortAlbumsTracksChronologically, + sortByCount, +} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({trackData}) { + return {trackData}; + }, + + query({trackData}, spec) { + const tracks = sortAlbumsTracksChronologically(trackData.slice()); + const timesReferenced = tracks.map(track => track.referencedByTracks.length); + + filterByCount(tracks, timesReferenced); + sortByCount(tracks, timesReferenced, {greatestFirst: true}); + + return {spec, tracks, timesReferenced}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + trackLinks: + query.tracks + .map(track => relation('linkTrack', track)), + }; + }, + + data(query) { + return { + timesReferenced: query.timesReferenced, + }; + }, + + generate(data, relations, {language}) { + return relations.page.slots({ + type: 'rows', + rows: + stitchArrays({ + link: relations.trackLinks, + timesReferenced: data.timesReferenced, + }).map(({link, timesReferenced}) => ({ + track: link, + timesReferenced: + language.countTimesReferenced(timesReferenced, {unit: true}), + })), + }); + }, +}; diff --git a/src/content/dependencies/listTracksInFlashesByAlbum.js b/src/content/dependencies/listTracksInFlashesByAlbum.js new file mode 100644 index 00000000..f2340eab --- /dev/null +++ b/src/content/dependencies/listTracksInFlashesByAlbum.js @@ -0,0 +1,82 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; +import {filterMultipleArrays, sortChronologically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkFlash', 'linkTrack'], + extraDependencies: ['language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query({albumData}, spec) { + const albums = sortChronologically(albumData.slice()); + + const tracks = + albums.map(album => + album.tracks.slice()); + + const flashes = + tracks.map(tracks => + tracks.map(track => + track.featuredInFlashes)); + + // Filter out tracks that aren't featured in any flashes. + // This listing doesn't perform any sorting within albums. + const stitched = stitchArrays({tracks, flashes}); + for (const {tracks, flashes} of stitched) { + filterMultipleArrays(tracks, flashes, + (tracks, flashes) => !empty(flashes)); + } + + // Filter out albums which don't have at least one remaining track. + filterMultipleArrays(albums, tracks, flashes, + (album, tracks, _flashes) => !empty(tracks)); + + return {spec, albums, tracks, flashes}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + + trackLinks: + query.tracks + .map(tracks => tracks + .map(track => relation('linkTrack', track))), + + flashLinks: + query.flashes + .map(flashesByAlbum => flashesByAlbum + .map(flashesByTrack => flashesByTrack + .map(flash => relation('linkFlash', flash)))), + }; + }, + + generate(relations, {language}) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + relations.albumLinks + .map(albumLink => ({album: albumLink})), + + chunkRows: + stitchArrays({ + trackLinks: relations.trackLinks, + flashLinks: relations.flashLinks, + }).map(({trackLinks, flashLinks}) => + stitchArrays({ + trackLink: trackLinks, + flashLinks: flashLinks, + }).map(({trackLink, flashLinks}) => ({ + track: trackLink, + flashes: language.formatConjunctionList(flashLinks), + }))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksInFlashesByFlash.js b/src/content/dependencies/listTracksInFlashesByFlash.js new file mode 100644 index 00000000..70edcd32 --- /dev/null +++ b/src/content/dependencies/listTracksInFlashesByFlash.js @@ -0,0 +1,69 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; +import {sortFlashesChronologically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkFlash', 'linkTrack'], + extraDependencies: ['wikiData'], + + sprawl({flashData}) { + return {flashData}; + }, + + query({flashData}, spec) { + const flashes = sortFlashesChronologically( + flashData + .filter(flash => !empty(flash.featuredTracks))); + + const tracks = + flashes.map(album => album.featuredTracks); + + const albums = + tracks.map(tracks => + tracks.map(track => track.album)); + + return {spec, flashes, tracks, albums}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + flashLinks: + query.flashes + .map(flash => relation('linkFlash', flash)), + + trackLinks: + query.tracks + .map(tracks => tracks + .map(track => relation('linkTrack', track))), + + albumLinks: + query.albums + .map(albums => albums + .map(album => relation('linkAlbum', album))), + }; + }, + + generate(relations) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + relations.flashLinks + .map(flashLink => ({flash: flashLink})), + + chunkRows: + stitchArrays({ + trackLinks: relations.trackLinks, + albumLinks: relations.albumLinks, + }).map(({trackLinks, albumLinks}) => + stitchArrays({ + trackLink: trackLinks, + albumLink: albumLinks, + }).map(({trackLink, albumLink}) => ({ + track: trackLink, + album: albumLink, + }))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksWithExtra.js b/src/content/dependencies/listTracksWithExtra.js new file mode 100644 index 00000000..62878132 --- /dev/null +++ b/src/content/dependencies/listTracksWithExtra.js @@ -0,0 +1,81 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; +import {filterMultipleArrays, sortChronologically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generateListingPage', 'linkAlbum', 'linkTrack'], + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query(sprawl, spec, property, valueMode) { + const albums = + sortChronologically(sprawl.albumData.slice()); + + const tracks = + albums + .map(album => + album.tracks + .filter(track => { + switch (valueMode) { + case 'truthy': return !!track[property]; + case 'array': return !empty(track[property]); + default: return false; + } + })); + + filterMultipleArrays(albums, tracks, + (album, tracks) => !empty(tracks)); + + return {spec, albums, tracks}; + }, + + relations(relation, query) { + return { + page: relation('generateListingPage', query.spec), + + albumLinks: + query.albums + .map(album => relation('linkAlbum', album)), + + trackLinks: + query.tracks + .map(tracks => tracks + .map(track => relation('linkTrack', track))), + }; + }, + + data(query) { + return { + dates: + query.albums.map(album => album.date), + }; + }, + + slots: { + hash: {type: 'string'}, + }, + + generate(data, relations, slots, {language}) { + return relations.page.slots({ + type: 'chunks', + + chunkTitles: + stitchArrays({ + albumLink: relations.albumLinks, + date: data.dates, + }).map(({albumLink, date}) => ({ + album: albumLink, + date: language.formatDate(date), + })), + + chunkRows: + relations.trackLinks + .map(trackLinks => trackLinks + .map(trackLink => ({ + track: trackLink.slot('hash', slots.hash), + }))), + }); + }, +}; diff --git a/src/content/dependencies/listTracksWithLyrics.js b/src/content/dependencies/listTracksWithLyrics.js new file mode 100644 index 00000000..a13a76f0 --- /dev/null +++ b/src/content/dependencies/listTracksWithLyrics.js @@ -0,0 +1,9 @@ +export default { + contentDependencies: ['listTracksWithExtra'], + + relations: (relation, spec) => + ({page: relation('listTracksWithExtra', spec, 'lyrics', 'truthy')}), + + generate: (relations) => + relations.page, +}; diff --git a/src/content/dependencies/listTracksWithMidiProjectFiles.js b/src/content/dependencies/listTracksWithMidiProjectFiles.js new file mode 100644 index 00000000..418af4c2 --- /dev/null +++ b/src/content/dependencies/listTracksWithMidiProjectFiles.js @@ -0,0 +1,9 @@ +export default { + contentDependencies: ['listTracksWithExtra'], + + relations: (relation, spec) => + ({page: relation('listTracksWithExtra', spec, 'midiProjectFiles', 'array')}), + + generate: (relations) => + relations.page.slot('hash', 'midi-project-files'), +}; diff --git a/src/content/dependencies/listTracksWithSheetMusicFiles.js b/src/content/dependencies/listTracksWithSheetMusicFiles.js new file mode 100644 index 00000000..0c6761eb --- /dev/null +++ b/src/content/dependencies/listTracksWithSheetMusicFiles.js @@ -0,0 +1,9 @@ +export default { + contentDependencies: ['listTracksWithExtra'], + + relations: (relation, spec) => + ({page: relation('listTracksWithExtra', spec, 'sheetMusicFiles', 'array')}), + + generate: (relations) => + relations.page.slot('hash', 'sheet-music-files'), +}; -- cgit 1.3.0-6-gf8a5