« get me outta code hell

album page social embeds - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-12-28 21:56:54 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-12-28 21:56:54 -0400
commit65e77ad3a66cd61910f916a26da1f4ce7be54dcf (patch)
tree8283884f86b658a4403ab71575974de48ecbb08f
parentcfefc5017cc418d8356c65e40eb20c70c9afbc88 (diff)
album page social embeds
-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 28c0990..1fc7452 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 ab08cdc..e8245d6 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}.",