« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/page/album.js45
-rw-r--r--src/strings-default.json9
2 files changed, 54 insertions, 0 deletions
diff --git a/src/page/album.js b/src/page/album.js
index 28c09907..1fc74520 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -57,6 +57,31 @@ export function write(album, {wikiData}) {
 
   const listTag = getAlbumListTag(album);
 
+  const getSocialEmbedDescription = ({
+    getArtistString: _getArtistString,
+    language,
+  }) => {
+    const hasDuration = albumDuration > 0;
+    const hasTracks = album.tracks.length > 0;
+    const hasDate = !!album.date;
+    if (!hasDuration && !hasTracks && !hasDate) return '';
+
+    return language.formatString(
+      'albumPage.socialEmbed.body' + [
+        hasDuration && '.withDuration',
+        hasTracks && '.withTracks',
+        hasDate && '.withReleaseDate',
+      ].filter(Boolean).join(''),
+      Object.fromEntries([
+        hasDuration &&
+          ['duration', language.formatDuration(albumDuration)],
+        hasTracks &&
+          ['tracks', language.countTracks(album.tracks.length, {unit: true})],
+        hasDate &&
+          ['date', language.formatDate(album.date)],
+      ].filter(Boolean)));
+  };
+
   const data = {
     type: 'data',
     path: ['album', album.directory],
@@ -98,6 +123,7 @@ export function write(album, {wikiData}) {
     type: 'page',
     path: ['album', album.directory],
     page: ({
+      absoluteTo,
       fancifyURL,
       generateAdditionalFilesShortcut,
       generateAdditionalFilesList,
@@ -139,6 +165,25 @@ export function write(album, {wikiData}) {
             ],
           }),
 
+        socialEmbed: {
+          heading:
+            (empty(album.groups)
+              ? ''
+              : language.$('albumPage.socialEmbed.heading', {
+                  group: album.groups[0].name,
+                })),
+          headingLink:
+            (empty(album.groups)
+              ? null
+              : absoluteTo('localized.album', album.groups[0].directory)),
+          title: language.$('albumPage.socialEmbed.title', {
+            album: album.name,
+          }),
+          description: getSocialEmbedDescription({getArtistString, language}),
+          image: '/' + getAlbumCover(album, {to: urls.from('shared.root').to}),
+          color: album.color,
+        },
+
         banner: !empty(album.bannerArtistContribs) && {
           dimensions: album.bannerDimensions,
           path: [
diff --git a/src/strings-default.json b/src/strings-default.json
index ab08cdca..e8245d6c 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -202,6 +202,15 @@
   "albumPage.nav.randomTrack": "Random Track",
   "albumPage.nav.gallery": "Gallery",
   "albumPage.nav.commentary": "Commentary",
+  "albumPage.socialEmbed.heading": "{GROUP}",
+  "albumPage.socialEmbed.title": "{ALBUM}",
+  "albumPage.socialEmbed.body.withDuration": "{DURATION}.",
+  "albumPage.socialEmbed.body.withTracks": "{TRACKS}.",
+  "albumPage.socialEmbed.body.withReleaseDate": "Released {DATE}.",
+  "albumPage.socialEmbed.body.withDuration.withTracks": "{DURATION}, {TRACKS}.",
+  "albumPage.socialEmbed.body.withDuration.withReleaseDate": "{DURATION}. Released {DATE}.",
+  "albumPage.socialEmbed.body.withTracks.withReleaseDate": "{TRACKS}. Released {DATE}.",
+  "albumPage.socialEmbed.body.withDuration.withTracks.withReleaseDate": "{DURATION}, {TRACKS}. Released {DATE}.",
   "albumGalleryPage.title": "{ALBUM} - Gallery",
   "albumGalleryPage.infoLine": "{TRACKS} totaling {DURATION}.",
   "albumGalleryPage.infoLine.withDate": "{TRACKS} totaling {DURATION}. Released {DATE}.",