diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-19 16:07:43 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-19 16:07:43 -0300 |
commit | 7411fe87dc667b25f265f5388b790c5d4bbc880d (patch) | |
tree | b730659ccf9399d492175fe36396dda8589df285 /src/content | |
parent | c6e1a0b6fb9314186a46cf1352a8685e8aa5fe8d (diff) |
data steps: draft relations + clean lint errors
Diffstat (limited to 'src/content')
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', |