« get me outta code hell

write: static-build, live-dev-server: path.condition() - 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>2025-02-05 16:07:31 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-05 16:08:55 -0400
commit4d5465b69989d50131ade81bc1cb8a929c64fc70 (patch)
treee286d438b636409924fe82411673f5dbdec8f873
parent2cd8c5b4b7a9e674900cdecfeee7c3bd850124bd (diff)
write: static-build, live-dev-server: path.condition()
-rw-r--r--src/write/build-modes/live-dev-server.js6
-rw-r--r--src/write/build-modes/static-build.js5
2 files changed, 9 insertions, 2 deletions
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index 28969de2..cd84dcc0 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -389,7 +389,11 @@ export async function go({
     // URL to page map expects trailing slash but no leading slash.
     const pathnameKey = pathname.replace(/^\//, '') + (pathname.endsWith('/') ? '' : '/');
 
-    if (!Object.hasOwn(urlToPageMap, pathnameKey)) {
+    const is404 =
+      !Object.hasOwn(urlToPageMap, pathnameKey) ||
+      !(urlToPageMap[pathnameKey].page.condition?.() ?? true);
+
+    if (is404) {
       response.writeHead(404, contentTypePlain);
       response.end(`No page found for: ${pathnameKey}\n`);
       if (loudResponses) console.log(`${requestHead} [404] ${pathname} (no page)`);
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 7eb73474..2baed816 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -195,7 +195,7 @@ export async function go({
           return null;
         }
 
-        const paths = [];
+        let paths = [];
 
         if (pageSpec.pathsTargetless) {
           const result = pageSpec.pathsTargetless({wikiData});
@@ -225,6 +225,9 @@ export async function go({
           // TODO: Validate each pathsForTargets entry
         }
 
+        paths =
+          paths.filter(path => path.condition?.() ?? true);
+
         return paths;
       })
       .filter(Boolean)