« get me outta code hell

social embeds (discord, maybe twitter) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-05-15 23:50:42 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-05-15 23:50:42 -0300
commitebded2fc40c3ff2faead343b9f68d768e6db2c32 (patch)
tree73aee0ff6437053f11fd63691945b6b0e62d6557 /src/page
parent44104a8970a10dff2894745f0c904644ca3234e0 (diff)
social embeds (discord, maybe twitter)
Tracks only for now, but more will come Soon(TM)!
Diffstat (limited to 'src/page')
-rw-r--r--src/page/track.js38
1 files changed, 37 insertions, 1 deletions
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 && {