From 64b4a5e6355872c49429f1d19c3403277d032b6c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 24 Jun 2023 17:55:00 -0300 Subject: content: linkContribution: take standard {who, what} object This is what's used for all contributions anyway, so no need to have every call to linkContribution manually destructure whatever contribution is being provided. --- .../dependencies/generateAlbumTrackListItem.js | 2 +- .../generateReleaseInfoContributionsLine.js | 3 +- src/content/dependencies/generateTrackInfoPage.js | 4 +- src/content/dependencies/generateTrackList.js | 4 +- src/content/dependencies/linkContribution.js | 19 ++++---- test/snapshot/linkContribution.js | 51 ++++++++++------------ test/unit/content/dependencies/linkContribution.js | 12 ++--- 7 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js index b750ddb1..761a4b50 100644 --- a/src/content/dependencies/generateAlbumTrackListItem.js +++ b/src/content/dependencies/generateAlbumTrackListItem.js @@ -13,7 +13,7 @@ export default { relations.contributionLinks = track.artistContribs - .map(({who, what}) => relation('linkContribution', who, what)); + .map(contrib => relation('linkContribution', contrib)); relations.trackLink = relation('linkTrack', track); diff --git a/src/content/dependencies/generateReleaseInfoContributionsLine.js b/src/content/dependencies/generateReleaseInfoContributionsLine.js index 78d3e506..5a97e651 100644 --- a/src/content/dependencies/generateReleaseInfoContributionsLine.js +++ b/src/content/dependencies/generateReleaseInfoContributionsLine.js @@ -13,8 +13,7 @@ export default { contributionLinks: contributions .slice(0, 4) - .map(({who, what}) => - relation('linkContribution', who, what)), + .map(contrib => relation('linkContribution', contrib)), }; }, diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js index 9ea8efab..c4596f14 100644 --- a/src/content/dependencies/generateTrackInfoPage.js +++ b/src/content/dependencies/generateTrackInfoPage.js @@ -150,8 +150,8 @@ export default { relation('generateContentHeading'); contributors.contributionLinks = - track.contributorContribs.map(({who, what}) => - relation('linkContribution', who, what)); + track.contributorContribs + .map(contrib => relation('linkContribution', contrib)); } // Section: Referenced tracks diff --git a/src/content/dependencies/generateTrackList.js b/src/content/dependencies/generateTrackList.js index 6688a33d..d0f14618 100644 --- a/src/content/dependencies/generateTrackList.js +++ b/src/content/dependencies/generateTrackList.js @@ -16,8 +16,8 @@ export default { relation('linkTrack', track), contributionLinks: - track.artistContribs.map(contrib => - relation('linkContribution', contrib.who, contrib.what)), + track.artistContribs + .map(contrib => relation('linkContribution', contrib)), })), }; }, diff --git a/src/content/dependencies/linkContribution.js b/src/content/dependencies/linkContribution.js index c9b514fe..f4c05388 100644 --- a/src/content/dependencies/linkContribution.js +++ b/src/content/dependencies/linkContribution.js @@ -11,14 +11,15 @@ export default { 'language', ], - relations(relation, artist) { + relations(relation, contribution) { const relations = {}; - relations.artistLink = relation('linkArtist', artist); + relations.artistLink = + relation('linkArtist', contribution.who); - if (!empty(artist.urls)) { + if (!empty(contribution.who.urls)) { relations.artistIcons = - artist.urls + contribution.who.urls .slice(0, 4) .map(url => relation('linkExternalAsIcon', url)); } @@ -26,8 +27,10 @@ export default { return relations; }, - data(artist, contribution) { - return {contribution}; + data(contribution) { + return { + what: contribution.what, + }; }, slots: { @@ -36,7 +39,7 @@ export default { }, generate(data, relations, slots, {html, language}) { - const hasContributionPart = !!(slots.showContribution && data.contribution); + const hasContributionPart = !!(slots.showContribution && data.what); const hasExternalPart = !!(slots.showIcons && relations.artistIcons); const externalLinks = hasExternalPart && @@ -49,7 +52,7 @@ export default { if (hasContributionPart) { parts.push('withContribution'); - options.contrib = data.contribution; + options.contrib = data.what; } if (hasExternalPart) { diff --git a/test/snapshot/linkContribution.js b/test/snapshot/linkContribution.js index 44033ad3..10b1bd08 100644 --- a/test/snapshot/linkContribution.js +++ b/test/snapshot/linkContribution.js @@ -2,37 +2,33 @@ import t from 'tap'; import {testContentFunctions} from '../lib/content-function.js'; testContentFunctions(t, 'linkContribution (snapshot)', async (t, evaluate) => { - const who1 = { - name: 'Clark Powell', - directory: 'clark-powell', - urls: ['https://soundcloud.com/plazmataz'], - }; - - const who2 = { - name: 'Grounder & Scratch', - directory: 'the-big-baddies', - urls: [], - }; - - const who3 = { - name: 'Toby Fox', - directory: 'toby-fox', - urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'], - }; - - const what1 = null; - const what2 = 'Snooping'; - const what3 = 'Arrangement'; - await evaluate.load(); const quickSnapshot = (message, slots) => evaluate.snapshot(message, { name: 'linkContribution', multiple: [ - {args: [who1, what1]}, - {args: [who2, what2]}, - {args: [who3, what3]}, + {args: [ + {who: { + name: 'Clark Powell', + directory: 'clark-powell', + urls: ['https://soundcloud.com/plazmataz'], + }, what: null}, + ]}, + {args: [ + {who: { + name: 'Grounder & Scratch', + directory: 'the-big-baddies', + urls: [], + }, what: 'Snooping'}, + ]}, + {args: [ + {who: { + name: 'Toby Fox', + directory: 'toby-fox', + urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'], + }, what: 'Arrangement'}, + ]}, ], slots, }); @@ -55,7 +51,7 @@ testContentFunctions(t, 'linkContribution (snapshot)', async (t, evaluate) => { evaluate.snapshot('loads of links', { name: 'linkContribution', args: [ - {name: 'Lorem Ipsum Lover', directory: 'lorem-ipsum-lover', urls: [ + {who: {name: 'Lorem Ipsum Lover', directory: 'lorem-ipsum-lover', urls: [ 'https://loremipsum.io', 'https://loremipsum.io/generator/', 'https://loremipsum.io/#meaning', @@ -64,8 +60,7 @@ testContentFunctions(t, 'linkContribution (snapshot)', async (t, evaluate) => { 'https://loremipsum.io/#when-to-use-lorem-ipsum', 'https://loremipsum.io/#lorem-ipsum-all-the-things', 'https://loremipsum.io/#original-source', - ]}, - null, + ]}, what: null}, ], slots: {showIcons: true}, }); diff --git a/test/unit/content/dependencies/linkContribution.js b/test/unit/content/dependencies/linkContribution.js index 6f3150f7..bed2b6d5 100644 --- a/test/unit/content/dependencies/linkContribution.js +++ b/test/unit/content/dependencies/linkContribution.js @@ -64,9 +64,9 @@ t.test('generateContributionLinks (unit)', async t => { evaluate({ name: 'linkContribution', multiple: [ - {args: [who1, what1]}, - {args: [who2, what2]}, - {args: [who3, what3]}, + {args: [{who: who1, what: what1}]}, + {args: [{who: who2, what: what2}]}, + {args: [{who: who3, what: what3}]}, ], slots, }); @@ -112,9 +112,9 @@ t.test('generateContributionLinks (unit)', async t => { evaluate({ name: 'linkContribution', multiple: [ - {args: [who1, what1]}, - {args: [who2, what2]}, - {args: [who3, what3]}, + {args: [{who: who1, what: what1}]}, + {args: [{who: who2, what: what2}]}, + {args: [{who: who3, what: what3}]}, ], slots, }); -- cgit 1.3.0-6-gf8a5