From ebded2fc40c3ff2faead343b9f68d768e6db2c32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 15 May 2022 23:50:42 -0300 Subject: social embeds (discord, maybe twitter) Tracks only for now, but more will come Soon(TM)! --- src/page/track.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/page') diff --git a/src/page/track.js b/src/page/track.js index 5249ea44..3295d48a 100644 --- a/src/page/track.js +++ b/src/page/track.js @@ -116,10 +116,36 @@ export function write(track, {wikiData}) { }) }; + const getSocialEmbedDescription = ({ + getArtistString: _getArtistString, + language, + }) => { + const hasArtists = (track.artistContribs?.length > 0); + const hasCoverArtists = (track.coverArtistContribs?.length > 0); + 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))) + }; + const page = { type: 'page', path: ['track', track.directory], page: ({ + absoluteTo, fancifyURL, generateChronologyLinks, generateCoverLink, @@ -134,7 +160,8 @@ export function write(track, {wikiData}) { transformInline, transformLyrics, transformMultiline, - to + to, + urls, }) => { const generateTrackList = bindOpts(unbound_generateTrackList, {getArtistString, link, language}); const cover = getTrackCover(track); @@ -147,6 +174,15 @@ export function write(track, {wikiData}) { `--track-directory: ${track.directory}` ]), + 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, + }, + // disabled for now! shifting banner position per height of page is disorienting /* banner: album.bannerArtistContribs.length && { -- cgit 1.3.0-6-gf8a5