« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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 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([
       `<!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 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),