« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page/track.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/page/track.js')
-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 && {