From 2da0d55d67c099defa7058dcb558f6ea7e0d2651 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Sep 2024 17:30:55 -0300 Subject: content: generateTrackSocialEmbedDescription: implement this Geez --- .../dependencies/generateTrackSocialEmbed.js | 18 +----- .../generateTrackSocialEmbedDescription.js | 73 +++++++++++----------- 2 files changed, 40 insertions(+), 51 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/generateTrackSocialEmbed.js b/src/content/dependencies/generateTrackSocialEmbed.js index 9868f0e2..d8e21e38 100644 --- a/src/content/dependencies/generateTrackSocialEmbed.js +++ b/src/content/dependencies/generateTrackSocialEmbed.js @@ -47,6 +47,9 @@ export default { track: data.trackName, }), + description: + relations.description, + headingContent: language.$(embedCapsule, 'heading', { album: data.albumName, @@ -69,18 +72,3 @@ export default { : null), })), }; - -/* - socialEmbed: { - heading: language.$('trackPage.socialEmbed.heading', { - album: track.album.name, - }), - headingLink: absoluteTo('localized.album', album.directory), - title: language.$('trackPage.socialEmbed.title', { - track: track.name, - }), - description: getSocialEmbedDescription({getArtistString, language}), - image: '/' + getTrackCover(track, {to: urls.from('shared.root').to}), - color: track.color, - }, -*/ diff --git a/src/content/dependencies/generateTrackSocialEmbedDescription.js b/src/content/dependencies/generateTrackSocialEmbedDescription.js index cf21eadf..4706aa26 100644 --- a/src/content/dependencies/generateTrackSocialEmbedDescription.js +++ b/src/content/dependencies/generateTrackSocialEmbedDescription.js @@ -1,38 +1,39 @@ +import {empty} from '#sugar'; + export default { - generate() { - }, -}; + extraDependencies: ['html', 'language'], + + data: (track) => ({ + artistNames: + track.artistContribs + .map(contrib => contrib.artist.name), + + coverArtistNames: + track.coverArtistContribs + .map(contrib => contrib.artist.name), + }), -/* - const getSocialEmbedDescription = ({ - getArtistString: _getArtistString, - language, - }) => { - const hasArtists = !empty(track.artistContribs); - const hasCoverArtists = !empty(track.coverArtistContribs); - const getArtistString = (contribs) => - _getArtistString(contribs, { - // We don't want to put actual HTML tags in social embeds (sadly - // they don't get parsed and displayed, generally speaking), so - // override the link argument so that artist "links" just show - // their names. - link: {artist: (artist) => artist.name}, - }); - if (!hasArtists && !hasCoverArtists) return ''; - return language.formatString( - 'trackPage.socialEmbed.body' + - [hasArtists && '.withArtists', hasCoverArtists && '.withCoverArtists'] - .filter(Boolean) - .join(''), - Object.fromEntries( - [ - hasArtists && ['artists', getArtistString(track.artistContribs)], - hasCoverArtists && [ - 'coverArtists', - getArtistString(track.coverArtistContribs), - ], - ].filter(Boolean) - ) - ); - }; -*/ + generate: (data, {html, language}) => + language.encapsulate('trackPage.socialEmbed.body', baseCapsule => + language.encapsulate(baseCapsule, workingCapsule => { + const workingOptions = {}; + + if (!empty(data.artistNames)) { + workingCapsule += '.withArtists'; + workingOptions.artists = + language.formatConjunctionList(data.artistNames); + } + + if (!empty(data.coverArtistNames)) { + workingCapsule += '.withCoverArtists'; + workingOptions.coverArtists = + language.formatConjunctionList(data.coverArtistNames); + } + + if (workingCapsule === baseCapsule) { + return html.blank(); + } else { + return language.$(workingCapsule, workingOptions); + } + })), +}; -- cgit 1.3.0-6-gf8a5