From e2cdee25fa4d7464f8429a951fe368b96ee48834 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 2 Aug 2023 18:04:17 -0300 Subject: content: generate{Album,Track}?SocialEmbed --- src/content/dependencies/generateSocialEmbed.js | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/content/dependencies/generateSocialEmbed.js (limited to 'src/content/dependencies/generateSocialEmbed.js') diff --git a/src/content/dependencies/generateSocialEmbed.js b/src/content/dependencies/generateSocialEmbed.js new file mode 100644 index 00000000..0144c7fb --- /dev/null +++ b/src/content/dependencies/generateSocialEmbed.js @@ -0,0 +1,65 @@ +export default { + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({wikiInfo}) { + return { + canonicalBase: wikiInfo.canonicalBase, + shortWikiName: wikiInfo.nameShort, + }; + }, + + data(sprawl) { + return { + canonicalBase: sprawl.canonicalBase, + shortWikiName: sprawl.shortWikiName, + }; + }, + + slots: { + mode: {validate: v => v.is('html', 'json')}, + + title: {type: 'string'}, + description: {type: 'string'}, + + headingContent: {type: 'string'}, + headingLink: {type: 'string'}, + imagePath: {type: 'string'}, + }, + + generate(data, slots, {html, language}) { + switch (slots.mode) { + case 'html': + return html.tags([ + slots.title && + html.tag('meta', {property: 'og:title', content: slots.title}), + + slots.description && + html.tag('meta', { + property: 'og:description', + content: slots.description, + }), + + slots.imagePath && + html.tag('meta', {property: 'og:image', content: slots.imagePath}), + ]); + + case 'json': + return JSON.stringify({ + author_name: + (slots.headingContent + ? language.$('misc.socialEmbed.heading', { + wikiName: data.shortWikiName, + heading: slots.headingContent, + }) + : undefined), + + author_url: + (slots.headingLink && data.canonicalBase + ? data.canonicalBase.replace(/\/$/, '') + + '/' + + slots.headingLink.replace(/^\//, '') + : undefined), + }); + } + }, +}; -- cgit 1.3.0-6-gf8a5