diff options
Diffstat (limited to 'src/content/dependencies')
4 files changed, 150 insertions, 6 deletions
diff --git a/src/content/dependencies/generateAlbumSocialEmbed.js b/src/content/dependencies/generateAlbumSocialEmbed.js index b5c5ef66..87d8eed2 100644 --- a/src/content/dependencies/generateAlbumSocialEmbed.js +++ b/src/content/dependencies/generateAlbumSocialEmbed.js @@ -11,13 +11,11 @@ export default { 'urls', ], - relations(album) { + relations(relation, album) { const relations = {}; - relations.description = { - dependency: 'generateAlbumSocialEmbedDescription', - args: [album], - }; + relations.description = + relation('generateAlbumSocialEmbedDescription', album); return relations; }, diff --git a/src/content/dependencies/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStylesheet.js index 491a7be6..c9547836 100644 --- a/src/content/dependencies/generateAlbumStylesheet.js +++ b/src/content/dependencies/generateAlbumStylesheet.js @@ -5,7 +5,7 @@ export default { 'to', ], - data: function(album) { + data(album) { const data = {}; data.hasWallpaper = !empty(album.wallpaperArtistContribs); diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js new file mode 100644 index 00000000..fb315cb1 --- /dev/null +++ b/src/content/dependencies/generateAlbumTrackListItem.js @@ -0,0 +1,66 @@ +import {compareArrays} from '../../util/sugar.js'; + +export default { + contentDependencies: [ + 'generateContributionLinks', + 'linkTrack', + ], + + extraDependencies: [ + 'getLinkThemeString', + 'html', + 'language', + ], + + relations(relation, track) { + const relations = {}; + + relations.contributionLinks = + relation('generateContributionLinks', track.artistContribs, { + showContribution: false, + showIcons: false, + }); + + relations.trackLink = + relation('linkTrack', track); + + return relations; + }, + + data(track) { + const data = {}; + + data.color = track.color; + data.duration = track.duration ?? 0; + + data.showArtists = + !compareArrays( + track.artistContribs.map(c => c.who), + track.album.artistContribs.map(c => c.who), + {checkOrder: false}); + }, + + generate(data, relations, { + getLinkThemeString, + html, + language, + }) { + const stringOpts = { + duration: language.formatDuration(data.duration), + track: relations.trackLink, + }; + + return html.tag('li', + {style: getLinkThemeString(data.color)}, + (!data.showArtists + ? language.$('trackList.item.withDuration', stringOpts) + : language.$('trackList.item.withDuration.withArtists', { + ...stringOpts, + by: + html.tag('span', {class: 'by'}, + language.$('trackList.item.withArtists.by', { + artists: relations.contributionLinks, + })), + }))); + }, +}; diff --git a/src/content/dependencies/generateContributionLinks.js b/src/content/dependencies/generateContributionLinks.js new file mode 100644 index 00000000..74695796 --- /dev/null +++ b/src/content/dependencies/generateContributionLinks.js @@ -0,0 +1,80 @@ +import {empty} from '../../util/sugar.js'; + +export default { + contentDependencies: [ + 'linkArtist', + ], + + relations(relation, contributions) { + const relations = {}; + + relations.artistLinks = + contributions.map(({who}) => relation('linkArtist', who)); + + return relations; + }, + + data(contributions, { + showContribution = false, + showIcons = false, + }) { + const data = {}; + + data.showContribution = showContribution; + data.showIcons = showIcons; + + data.contributionData = + contributions.map(({who, what}) => ({ + hasContributionPart: !!(showContribution && what), + hasExternalPart: !!(showIcons && !empty(who.urls)), + artistUrls: who.urls, + contribution: showContribution && what, + })); + + return data; + }, + + generate(data, relations, { + html, + iconifyURL, + language, + }) { + return language.formatConjunctionList( + data.contributionData.map(({ + hasContributionPart, + hasExternalPart, + artistUrls, + contribution, + }, index) => { + const artistLink = relations.artistLinks[index]; + + const externalLinks = hasExternalPart && + html.tag('span', + {[html.noEdgeWhitespace]: true, class: 'icons'}, + language.formatUnitList( + artistUrls.map(url => iconifyURL(url, {language})))); + + return ( + (hasContributionPart + ? (hasExternalPart + ? language.$('misc.artistLink.withContribution.withExternalLinks', { + artist: artistLink, + contrib: contribution, + links: externalLinks, + }) + : language.$('misc.artistLink.withContribution', { + artist: artistLink, + contrib: contribution, + })) + : (hasExternalPart + ? language.$('misc.artistLink.withExternalLinks', { + artist: artistLink, + links: externalLinks, + }) + : language.$('misc.artistLink', { + artist: artistLink, + }))) + ); + })); + }, +}; |