From 019e351a9560b09256dfaf99fea9252029df1701 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 10 Apr 2024 19:39:41 -0300 Subject: content: gAIPOtherArtistLinks: use associatedContributions --- .../generateArtistInfoPageOtherArtistLinks.js | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js') diff --git a/src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js b/src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js index 471ee26c..dcee9c00 100644 --- a/src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js +++ b/src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js @@ -1,24 +1,30 @@ -import {empty} from '#sugar'; +import {unique} from '#sugar'; export default { contentDependencies: ['linkArtist'], - relations(relation, contribs, artist) { - const otherArtistContribs = - contribs.filter(contrib => contrib.artist !== artist); + query(contribs) { + const associatedContributionsByOtherArtists = + contribs + .flatMap(ownContrib => + ownContrib.associatedContributions + .filter(associatedContrib => + associatedContrib.artist !== ownContrib.artist)); - if (empty(otherArtistContribs)) { - return {}; - } + const otherArtists = + unique( + associatedContributionsByOtherArtists + .map(contrib => contrib.artist)); - const otherArtistLinks = - otherArtistContribs - .map(contrib => relation('linkArtist', contrib.artist)); - - return {otherArtistLinks}; + return {otherArtists}; }, - generate(relations) { - return relations.otherArtistLinks ?? null; - }, + relations: (relation, query) => ({ + artistLinks: + query.otherArtists + .map(artist => relation('linkArtist', artist)), + }), + + generate: (relations) => + relations.artistLinks, }; -- cgit 1.3.0-6-gf8a5