diff options
Diffstat (limited to 'src/content/dependencies')
3 files changed, 35 insertions, 15 deletions
diff --git a/src/content/dependencies/generateAlbumSocialEmbed.js b/src/content/dependencies/generateAlbumSocialEmbed.js index 699b3d26..b5c5ef66 100644 --- a/src/content/dependencies/generateAlbumSocialEmbed.js +++ b/src/content/dependencies/generateAlbumSocialEmbed.js @@ -1,21 +1,29 @@ +import {accumulateSum, empty} from '../../util/sugar.js'; + export default { contentDependencies: [ - 'generateSocialEmbedDescription', + 'generateAlbumSocialEmbedDescription', ], extraDependencies: [ 'absoluteTo', 'language', - 'to', 'urls', ], - data(album, { - generateSocialEmbedDescription, - }) { - const data = {}; + relations(album) { + const relations = {}; + + relations.description = { + dependency: 'generateAlbumSocialEmbedDescription', + args: [album], + }; + + return relations; + }, - data.descriptionData = generateSocialEmbedDescription.data(album); + data(album) { + const data = {}; data.hasHeading = !empty(album.groups); @@ -25,18 +33,22 @@ export default { data.headingGroupDirectory = firstGroup.directory; } + data.hasImage = album.hasCoverArt; + + if (data.hasImage) { + data.coverArtDirectory = album.directory; + data.coverArtFileExtension = album.coverArtFileExtension; + } + data.albumName = album.name; data.albumColor = album.color; return data; }, - generate(data, { - generateSocialEmbedDescription, - + generate(data, relations, { absoluteTo, language, - to, urls, }) { const socialEmbed = {}; @@ -59,10 +71,14 @@ export default { album: data.albumName, }); - socialEmbed.description = generateSocialEmbedDescription(data.descriptionData); + socialEmbed.description = relations.description; - socialEmbed.image = - '/' + getAlbumCover(album, {to: urls.from('shared.root').to}); + if (data.hasImage) { + const imagePath = urls + .from('shared.root') + .to('media.albumColor', data.coverArtDirectory, data.coverArtFileExtension); + socialEmbed.image = '/' + imagePath; + } socialEmbed.color = data.albumColor; diff --git a/src/content/dependencies/generateAlbumSocialEmbedDescription.js b/src/content/dependencies/generateAlbumSocialEmbedDescription.js index 2bb62596..5fa67b26 100644 --- a/src/content/dependencies/generateAlbumSocialEmbedDescription.js +++ b/src/content/dependencies/generateAlbumSocialEmbedDescription.js @@ -1,10 +1,12 @@ +import {accumulateSum} from '../../util/sugar.js'; + export default { extraDependencies: ['language'], data(album) { const data = {}; - const duration = getTotalDuration(album); + const duration = accumulateSum(album.tracks, track => track.duration); data.hasDuration = duration > 0; data.hasTracks = album.tracks.length > 0; diff --git a/src/content/dependencies/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStylesheet.js index 575f7d59..491a7be6 100644 --- a/src/content/dependencies/generateAlbumStylesheet.js +++ b/src/content/dependencies/generateAlbumStylesheet.js @@ -1,3 +1,5 @@ +import {empty} from '../../util/sugar.js'; + export default { extraDependencies: [ 'to', |