From 42a06333e4ebf98f22cbb7a856ff4517ee47fcb1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 31 May 2024 23:21:56 -0300 Subject: content: gAIPFlashesChunkedList: general refactor a la tracks --- .../generateArtistInfoPageArtworksChunk.js | 4 - .../generateArtistInfoPageArtworksChunkedList.js | 2 - .../generateArtistInfoPageFlashesChunk.js | 34 +++++ .../generateArtistInfoPageFlashesChunkItem.js | 34 +++++ .../generateArtistInfoPageFlashesChunkedList.js | 162 +++++---------------- src/data/things/artist.js | 6 + 6 files changed, 109 insertions(+), 133 deletions(-) create mode 100644 src/content/dependencies/generateArtistInfoPageFlashesChunk.js create mode 100644 src/content/dependencies/generateArtistInfoPageFlashesChunkItem.js (limited to 'src') diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunk.js b/src/content/dependencies/generateArtistInfoPageArtworksChunk.js index b62cb39b..2b10df3e 100644 --- a/src/content/dependencies/generateArtistInfoPageArtworksChunk.js +++ b/src/content/dependencies/generateArtistInfoPageArtworksChunk.js @@ -12,10 +12,6 @@ export default { albumLink: relation('linkAlbum', album), - // Intentional mapping here: each item may be associated with - // more than one contribution. (Note: this is only currently - // applicable for track contributions, but we're retaining the - // structure in other contributions too.) items: contribs .map(contrib => diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js index ddab7eff..caefb7a3 100644 --- a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js +++ b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js @@ -8,8 +8,6 @@ export default { 'generateArtistInfoPageArtworksChunk', ], - extraDependencies: ['html', 'language'], - query(artist) { const query = {}; diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunk.js b/src/content/dependencies/generateArtistInfoPageFlashesChunk.js new file mode 100644 index 00000000..8aa7223a --- /dev/null +++ b/src/content/dependencies/generateArtistInfoPageFlashesChunk.js @@ -0,0 +1,34 @@ +export default { + contentDependencies: [ + 'generateArtistInfoPageChunk', + 'generateArtistInfoPageFlashesChunkItem', + 'linkFlashAct', + ], + + relations: (relation, flashAct, contribs) => ({ + template: + relation('generateArtistInfoPageChunk'), + + flashActLink: + relation('linkFlashAct', flashAct), + + items: + contribs + .map(contrib => + relation('generateArtistInfoPageFlashesChunkItem', contrib)), + }), + + data: (_flashAct, contribs) => ({ + dates: + contribs + .map(contrib => contrib.date), + }), + + generate: (data, relations) => + relations.template.slots({ + mode: 'flash', + flashActLink: relations.flashActLink, + dates: data.dates, + items: relations.items, + }), +}; diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkItem.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkItem.js new file mode 100644 index 00000000..e4908bf9 --- /dev/null +++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkItem.js @@ -0,0 +1,34 @@ +export default { + contentDependencies: ['generateArtistInfoPageChunkItem', 'linkFlash'], + + extraDependencies: ['language'], + + relations: (relation, contrib) => ({ + // Flashes and games can list multiple contributors as collaborative + // credits, but we don't display these on the artist page, since they + // usually involve many artists crediting a larger team where collaboration + // isn't as relevant (without more particular details that aren't tracked + // on the wiki). + + template: + relation('generateArtistInfoPageChunkItem'), + + flashLink: + relation('linkFlash', contrib.thing), + }), + + data: (contrib) => ({ + annotation: + contrib.annotation, + }), + + generate: (data, relations, {language}) => + relations.template.slots({ + annotation: data.annotation, + + content: + language.$('artistPage.creditList.entry.flash', { + flash: relations.flashLink, + }), + }), +}; diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js index 4338c7e6..a0eba8ff 100644 --- a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js +++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js @@ -1,144 +1,52 @@ -import {sortEntryThingPairs, sortFlashesChronologically} from '#sort'; -import {chunkByProperties, stitchArrays} from '#sugar'; +import {sortContributionsChronologically, sortFlashesChronologically} + from '#sort'; +import {chunkByConditions, stitchArrays} from '#sugar'; export default { contentDependencies: [ - 'generateArtistInfoPageChunk', - 'generateArtistInfoPageChunkItem', - 'linkFlash', + 'generateArtistInfoPageChunkedList', + 'generateArtistInfoPageFlashesChunk', ], - extraDependencies: ['html', 'language'], - query(artist) { - const processFlashEntry = ({flash, contribs}) => ({ - thing: flash, - entry: { - flash: flash, - act: flash.act, - contribs: contribs, - }, - }); - - const processFlashEntries = ({flashes, contribs}) => - stitchArrays({ - flash: flashes, - contribs: contribs, - }).map(processFlashEntry); - - const {flashesAsContributor} = artist; - - const flashesAsContributorContribs = - flashesAsContributor - .map(flash => flash.contributorContribs); + const query = {}; - const flashesAsContributorEntries = - processFlashEntries({ - flashes: flashesAsContributor, - contribs: flashesAsContributorContribs, - }); - - const entries = [ - ...flashesAsContributorEntries, + const allContributions = [ + ...artist.flashContributorContributions, ]; - sortEntryThingPairs(entries, sortFlashesChronologically); - - const chunks = - chunkByProperties( - entries.map(({entry}) => entry), - ['act']); - - return {chunks}; - }, - - relations(relation, query) { - // Flashes and games can list multiple contributors as collaborative - // credits, but we don't display these on the artist page, since they - // usually involve many artists crediting a larger team where collaboration - // isn't as relevant (without more particular details that aren't tracked - // on the wiki). + sortContributionsChronologically( + allContributions, + sortFlashesChronologically); - return { - chunks: - query.chunks.map(() => relation('generateArtistInfoPageChunk')), + query.contribs = + chunkByConditions(allContributions, [ + ({thing: flash1}, {thing: flash2}) => + flash1.act !== flash2.act, + ]); - actLinks: - query.chunks.map(({chunk}) => - relation('linkFlash', chunk[0].flash)), + query.flashActs = + query.contribs + .map(contribs => contribs[0].thing) + .map(thing => thing.act); - items: - query.chunks.map(({chunk}) => - chunk.map(() => relation('generateArtistInfoPageChunkItem'))), - - itemFlashLinks: - query.chunks.map(({chunk}) => - chunk.map(({flash}) => relation('linkFlash', flash))), - }; + return query; }, - data(query, artist) { - return { - actNames: - query.chunks.map(({act}) => act.name), - - dates: - query.chunks.map(({chunk}) => - chunk.map(({flash}) => flash.date)), + relations: (relation, query, _artist) => ({ + chunkedList: + relation('generateArtistInfoPageChunkedList'), - itemContributions: - query.chunks.map(({chunk}) => - chunk.map(({contribs}) => - contribs - .find(contrib => contrib.artist === artist) - .annotation)), - }; - }, - - generate(data, relations, {html, language}) { - return html.tag('dl', + chunks: stitchArrays({ - chunk: relations.chunks, - actLink: relations.actLinks, - actName: data.actNames, - dates: data.dates, - - items: relations.items, - itemFlashLinks: relations.itemFlashLinks, - itemContributions: data.itemContributions, - }).map(({ - chunk, - actLink, - actName, - dates, - - items, - itemFlashLinks, - itemContributions, - }) => - chunk.slots({ - mode: 'flash', - flashActLink: actLink.slot('content', actName), - dates, - - items: - stitchArrays({ - item: items, - flashLink: itemFlashLinks, - contribution: itemContributions, - }).map(({ - item, - flashLink, - contribution, - }) => - item.slots({ - annotation: contribution, - - content: - language.$('artistPage.creditList.entry.flash', { - flash: flashLink, - }), - })), - }))); - }, + flashAct: query.flashActs, + contribs: query.contribs, + }).map(({flashAct, contribs}) => + relation('generateArtistInfoPageFlashesChunk', flashAct, contribs)), + }), + + generate: (relations) => + relations.chunkedList.slots({ + chunks: relations.chunks, + }), }; diff --git a/src/data/things/artist.js b/src/data/things/artist.js index 6e148d1d..738f9c81 100644 --- a/src/data/things/artist.js +++ b/src/data/things/artist.js @@ -271,6 +271,12 @@ export class Artist extends Thing { list: input.value('commentatorArtists'), }), + flashContributorContributions: reverseContributionList({ + data: 'flashData', + list: input.value('contributorContribs'), + mode: input.value('contributions'), + }), + totalDuration: artistTotalDuration(), }); -- cgit 1.3.0-6-gf8a5