diff options
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 |
commit | 4d5465b69989d50131ade81bc1cb8a929c64fc70 (patch) | |
tree | e286d438b636409924fe82411673f5dbdec8f873 | |
parent | 2cd8c5b4b7a9e674900cdecfeee7c3bd850124bd (diff) |
write: static-build, live-dev-server: path.condition()
-rw-r--r-- | src/write/build-modes/live-dev-server.js | 6 | ||||
-rw-r--r-- | src/write/build-modes/static-build.js | 5 |
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) |