From c0d76a612f3a1db99c60f494d2bdcc05fa7c6679 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 30 Jun 2023 17:09:10 -0300 Subject: content: generateArtistInfoPageCommentaryChunkedList --- .../generateArtistInfoPageCommentaryChunkedList.js | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js (limited to 'src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js') diff --git a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js new file mode 100644 index 00000000..5e5e9819 --- /dev/null +++ b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js @@ -0,0 +1,111 @@ +import {stitchArrays} from '../../util/sugar.js'; + +import { + chunkByProperties, + sortAlbumsTracksChronologically, + sortEntryThingPairs, +} from '../../util/wiki-data.js'; + +export default { + contentDependencies: [ + 'generateArtistInfoPageChunk', + 'generateArtistInfoPageChunkItem', + 'generateArtistInfoPageOtherArtistLinks', + 'linkAlbum', + 'linkTrack', + ], + + extraDependencies: ['html', 'language'], + + query(artist) { + // TODO: Add and integrate wallpaper and banner date fields (#90) + // This will probably only happen once all artworks follow a standard + // shape (#70) and get their own sorting function. Read for more info: + // https://github.com/hsmusic/hsmusic-wiki/issues/90#issuecomment-1607422961 + + const entries = [ + ...artist.albumsAsCommentator.map(album => ({ + thing: album, + entry: { + type: 'album', + album, + }, + })), + + ...artist.tracksAsContributor.map(track => ({ + thing: track, + entry: { + type: 'track', + album: track.album, + track, + }, + })), + ]; + + sortEntryThingPairs(entries, sortAlbumsTracksChronologically); + + const chunks = + chunkByProperties( + entries.map(({entry}) => entry), + ['album']); + + return {chunks}; + }, + + relations(relation, query) { + return { + chunks: + query.chunks.map(() => relation('generateArtistInfoPageChunk')), + + albumLinks: + query.chunks.map(({album}) => relation('linkAlbum', album)), + + items: + query.chunks.map(({chunk}) => + chunk.map(() => relation('generateArtistInfoPageChunkItem'))), + + itemTrackLinks: + query.chunks.map(({chunk}) => + chunk.map(({track}) => track ? relation('linkTrack', track) : null)), + }; + }, + + data(query) { + return { + itemTypes: + query.chunks.map(({chunk}) => + chunk.map(({type}) => type)), + }; + }, + + generate(data, relations, {html, language}) { + return html.tag('dl', + stitchArrays({ + chunk: relations.chunks, + albumLink: relations.albumLinks, + + items: relations.items, + itemTrackLinks: relations.itemTrackLinks, + itemTypes: data.itemTypes, + }).map(({chunk, albumLink, items, itemTrackLinks, itemTypes}) => + chunk.slots({ + mode: 'album', + albumLink, + items: + stitchArrays({ + item: items, + trackLink: itemTrackLinks, + type: itemTypes, + }).map(({item, trackLink, type}) => + item.slots({ + content: + (type === 'album' + ? html.tag('i', + language.$('artistPage.creditList.entry.album.commentary')) + : language.$('artistPage.creditList.entry.track', { + track: trackLink, + })), + })), + }))); + }, +}; -- cgit 1.3.0-6-gf8a5