From cadeb88fac5d121d13ef517a043c0577d3e8b880 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 2 Aug 2023 18:03:17 -0300 Subject: content, infra: support social embeds --- src/content/dependencies/generatePageLayout.js | 20 +++++++++++++++++--- src/write/build-modes/live-dev-server.js | 2 +- src/write/build-modes/static-build.js | 13 +++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/content/dependencies/generatePageLayout.js b/src/content/dependencies/generatePageLayout.js index 706340cc..490468c9 100644 --- a/src/content/dependencies/generatePageLayout.js +++ b/src/content/dependencies/generatePageLayout.js @@ -210,6 +210,7 @@ export default { to, }) { const colors = getColors(slots.color ?? data.wikiColor); + const hasSocialEmbed = !html.isBlank(slots.socialEmbed); let titleHTML = null; @@ -522,7 +523,7 @@ export default { footerHTML, ].filter(Boolean).join('\n'); - return html.tags([ + const pageHTML = html.tags([ ``, html.tag('html', { @@ -601,7 +602,10 @@ export default { */ - // slots.socialEmbed, + hasSocialEmbed && + slots.socialEmbed + .clone() + .slot('mode', 'html'), html.tag('link', { rel: 'stylesheet', @@ -636,6 +640,16 @@ export default { }), ]), ]) - ]); + ]).toString(); + + const oEmbedJSON = + (hasSocialEmbed + ? slots.socialEmbed + .clone() + .slot('mode', 'json') + .content + : null); + + return {pageHTML, oEmbedJSON}; }, }; diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 1f74df1e..6734c065 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -365,7 +365,7 @@ export async function go({ args: page.contentFunction.args ?? [], }); - const pageHTML = topLevelResult.toString(); + const {pageHTML} = topLevelResult.content; if (!quietResponses) console.log(`${requestHead} [200] ${pathname}`); response.writeHead(200, contentTypeHTML); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 2a5e1437..8bc1b242 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -309,10 +309,11 @@ export async function go({ args: page.contentFunction.args ?? [], }); - const pageHTML = topLevelResult.toString(); + const {pageHTML, oEmbedJSON} = topLevelResult.content; return writePage({ - html: pageHTML, + pageHTML, + oEmbedJSON, outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, @@ -333,10 +334,10 @@ export async function go({ }); const target = to('localized.' + toPath[0], ...toPath.slice(1)); - const html = generateRedirectHTML(title, target, {language}); + const pageHTML = generateRedirectHTML(title, target, {language}); return writePage({ - html, + pageHTML, outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, @@ -387,14 +388,14 @@ import { } from 'fs/promises'; async function writePage({ - html, + pageHTML, oEmbedJSON = '', outputDirectory, }) { await mkdir(outputDirectory, {recursive: true}); await Promise.all([ - writeFile(path.join(outputDirectory, 'index.html'), html), + writeFile(path.join(outputDirectory, 'index.html'), pageHTML), oEmbedJSON && writeFile(path.join(outputDirectory, 'oembed.json'), oEmbedJSON), -- cgit 1.3.0-6-gf8a5