From 4d5465b69989d50131ade81bc1cb8a929c64fc70 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 5 Feb 2025 16:07:31 -0400 Subject: write: static-build, live-dev-server: path.condition() --- src/write/build-modes/live-dev-server.js | 6 +++++- src/write/build-modes/static-build.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') 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) -- cgit 1.3.0-6-gf8a5