diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-08-02 18:04:17 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-08-02 18:04:17 -0300 |
commit | e2cdee25fa4d7464f8429a951fe368b96ee48834 (patch) | |
tree | 1b40bd2fa1df70918fa58550177f3e6d75ecf1b6 /src/content/dependencies/generateSocialEmbed.js | |
parent | cadeb88fac5d121d13ef517a043c0577d3e8b880 (diff) |
content: generate{Album,Track}?SocialEmbed
Diffstat (limited to 'src/content/dependencies/generateSocialEmbed.js')
-rw-r--r-- | src/content/dependencies/generateSocialEmbed.js | 65 |
1 files changed, 65 insertions, 0 deletions
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), + }); + } + }, +}; |