From 79ac807130a48578cf32b1b2258c481121a1c7c7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 12 Jun 2024 13:16:39 -0300 Subject: content: generateTrackList: blank if no tracks --- src/content/dependencies/generateTrackList.js | 80 ++++++++++++--------------- 1 file changed, 36 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/content/dependencies/generateTrackList.js b/src/content/dependencies/generateTrackList.js index 3c36d248..4760ff2f 100644 --- a/src/content/dependencies/generateTrackList.js +++ b/src/content/dependencies/generateTrackList.js @@ -5,55 +5,47 @@ export default { extraDependencies: ['html', 'language'], - relations(relation, tracks) { - if (empty(tracks)) { - return {}; - } + relations: (relation, tracks) => ({ + trackLinks: + tracks + .map(track => relation('linkTrack', track)), - return { - trackLinks: - tracks - .map(track => relation('linkTrack', track)), - - contributionLinks: - tracks - .map(track => - (empty(track.artistContribs) - ? null - : track.artistContribs - .map(contrib => relation('linkContribution', contrib)))), - }; - }, + contributionLinks: + tracks + .map(track => + track.artistContribs + .map(contrib => relation('linkContribution', contrib))), + }), slots: { showContribution: {type: 'boolean', default: false}, showIcons: {type: 'boolean', default: false}, }, - generate(relations, slots, {html, language}) { - return ( - html.tag('ul', - stitchArrays({ - trackLink: relations.trackLinks, - contributionLinks: relations.contributionLinks, - }).map(({trackLink, contributionLinks}) => - html.tag('li', - (empty(contributionLinks) - ? trackLink - : language.$('trackList.item.withArtists', { - track: trackLink, - by: - html.tag('span', {class: 'by'}, - html.metatag('chunkwrap', {split: ','}, - language.$('trackList.item.withArtists.by', { - artists: - language.formatConjunctionList( - contributionLinks.map(link => - link.slots({ - showContribution: slots.showContribution, - showIcons: slots.showIcons, - }))), - }))), - })))))); - }, + generate: (relations, slots, {html, language}) => + html.tag('ul', + {[html.onlyIfContent]: true}, + + stitchArrays({ + trackLink: relations.trackLinks, + contributionLinks: relations.contributionLinks, + }).map(({trackLink, contributionLinks}) => + html.tag('li', + (empty(contributionLinks) + ? trackLink + : language.$('trackList.item.withArtists', { + track: trackLink, + by: + html.tag('span', {class: 'by'}, + html.metatag('chunkwrap', {split: ','}, + language.$('trackList.item.withArtists.by', { + artists: + language.formatConjunctionList( + contributionLinks.map(link => + link.slots({ + showContribution: slots.showContribution, + showIcons: slots.showIcons, + }))), + }))), + }))))), }; -- cgit 1.3.0-6-gf8a5