From 91cde73bb69944ec9ceabf8d23ce829df12dbb0a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 26 Jan 2025 16:56:47 -0400 Subject: content: generateSocialEmbed: process image path --- .../dependencies/generateAlbumSocialEmbed.js | 9 +++----- src/content/dependencies/generateSocialEmbed.js | 25 ++++++++++++++++++---- .../dependencies/generateTrackSocialEmbed.js | 14 ++++-------- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumSocialEmbed.js b/src/content/dependencies/generateAlbumSocialEmbed.js index 54574e45..ad02e180 100644 --- a/src/content/dependencies/generateAlbumSocialEmbed.js +++ b/src/content/dependencies/generateAlbumSocialEmbed.js @@ -6,7 +6,7 @@ export default { 'generateAlbumSocialEmbedDescription', ], - extraDependencies: ['absoluteTo', 'language', 'urls'], + extraDependencies: ['absoluteTo', 'language'], relations(relation, album) { return { @@ -41,7 +41,7 @@ export default { return data; }, - generate: (data, relations, {absoluteTo, language, urls}) => + generate: (data, relations, {absoluteTo, language}) => language.encapsulate('albumPage.socialEmbed', embedCapsule => relations.socialEmbed.slots({ title: @@ -65,10 +65,7 @@ export default { imagePath: (data.hasImage - ? '/' + - urls - .from('shared.root') - .to('media.albumCover', data.coverArtDirectory, data.coverArtFileExtension) + ? ['media.albumCover', data.coverArtDirectory, data.coverArtFileExtension] : null), })), }; diff --git a/src/content/dependencies/generateSocialEmbed.js b/src/content/dependencies/generateSocialEmbed.js index 85a0f4d3..115dc262 100644 --- a/src/content/dependencies/generateSocialEmbed.js +++ b/src/content/dependencies/generateSocialEmbed.js @@ -1,5 +1,7 @@ +import {getOrigin} from '#urls'; + export default { - extraDependencies: ['html', 'language', 'wikiData'], + extraDependencies: ['html', 'language', 'urls', 'wikiData'], sprawl({wikiInfo}) { return { @@ -23,10 +25,10 @@ export default { headingContent: {type: 'string'}, headingLink: {type: 'string'}, - imagePath: {type: 'string'}, + imagePath: {validate: v => v.strictArrayOf(v.isString)}, }, - generate(data, slots, {html, language}) { + generate(data, slots, {html, language, urls}) { switch (slots.mode) { case 'html': return html.tags([ @@ -40,7 +42,22 @@ export default { }), slots.imagePath && - html.tag('meta', {property: 'og:image', content: slots.imagePath}), + html.tag('meta', { + property: 'og:image', + content: + (() => { + const toResult = + urls + .from('shared.root') + .to(...slots.imagePath); + + if (getOrigin(toResult)) { + return toResult; + } else { + return '/' + toResult; + } + })(), + }), ]); case 'json': diff --git a/src/content/dependencies/generateTrackSocialEmbed.js b/src/content/dependencies/generateTrackSocialEmbed.js index d8e21e38..7cb37af2 100644 --- a/src/content/dependencies/generateTrackSocialEmbed.js +++ b/src/content/dependencies/generateTrackSocialEmbed.js @@ -4,7 +4,7 @@ export default { 'generateTrackSocialEmbedDescription', ], - extraDependencies: ['absoluteTo', 'language', 'urls'], + extraDependencies: ['absoluteTo', 'language'], relations(relation, track) { return { @@ -39,7 +39,7 @@ export default { return data; }, - generate: (data, relations, {absoluteTo, language, urls}) => + generate: (data, relations, {absoluteTo, language}) => language.encapsulate('trackPage.socialEmbed', embedCapsule => relations.socialEmbed.slots({ title: @@ -60,15 +60,9 @@ export default { imagePath: (data.imageSource === 'album' - ? '/' + - urls - .from('shared.root') - .to('media.albumCover', data.albumDirectory, data.coverArtFileExtension) + ? ['media.albumCover', data.albumDirectory, data.coverArtFileExtension] : data.imageSource === 'track' - ? '/' + - urls - .from('shared.root') - .to('media.trackCover', data.albumDirectory, data.trackDirectory, data.coverArtFileExtension) + ? ['media.trackCover', data.albumDirectory, data.trackDirectory, data.coverArtFileExtension] : null), })), }; -- cgit 1.3.0-6-gf8a5