« get me outta code hell

content, infra: support 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>2023-08-02 18:03:17 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-02 18:03:17 -0300
commitcadeb88fac5d121d13ef517a043c0577d3e8b880 (patch)
tree873575e7eda02f5df1e4ef98ea50a6c29d981438
parented55527ca510cd93bb035e3466e30ed6197928d9 (diff)
content, infra: support social embeds
-rw-r--r--src/content/dependencies/generatePageLayout.js20
-rw-r--r--src/write/build-modes/live-dev-server.js2
-rw-r--r--src/write/build-modes/static-build.js13
3 files changed, 25 insertions, 10 deletions
diff --git a/src/content/dependencies/generatePageLayout.js b/src/content/dependencies/generatePageLayout.js
index 706340c..490468c 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([
       `<!DOCTYPE html>`,
       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 1f74df1..6734c06 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 2a5e143..8bc1b24 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),