From 7411fe87dc667b25f265f5388b790c5d4bbc880d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 19 Mar 2023 16:07:43 -0300 Subject: data steps: draft relations + clean lint errors --- .../dependencies/generateAlbumSocialEmbed.js | 44 +++++++++++++++------- .../generateAlbumSocialEmbedDescription.js | 4 +- .../dependencies/generateAlbumStylesheet.js | 2 + 3 files changed, 35 insertions(+), 15 deletions(-) (limited to 'src') 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', -- cgit 1.3.0-6-gf8a5