Files
AndreaSlopFotografie/web/config/pageFiles.ts
T
SluijsensandClaude Opus 5.5 1574726c1d Adds the step that moves inline scripts to files
TanStack Start writes inline scripts into each page, which the strict CSP
blocks. This step moves them to hashed files and checks the output: every page
is present, no executable inline script remains and the e-mail address appears
nowhere. It is not part of the build yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 18:12:42 +01:00

27 lines
1.2 KiB
TypeScript

// Koppelt een paginapad aan het HTML-bestand in dist/client en terug. Eén
// afbeelding voor vite.config.ts (prerender), de script-runner en de
// preview-server, zodat ze nooit van mening verschillen over waar een pagina
// staat (BR-BLD-03).
export const NOT_FOUND_PATH = '/404';
export const NOT_FOUND_FILE = '404.html';
const EXTENSION = '.html';
// '/' wordt index.html, elk ander pad het pad zonder voorste slash plus .html
// (geen mappen en geen redirect naar een slash: autoSubfolderIndex staat uit)
export function pageFile(path: string): string {
if (path === '/') return `index${EXTENSION}`;
return `${path.replace(/^\//, '')}${EXTENSION}`;
}
// Omgekeerd: undefined voor 404.html en voor alles wat geen paginabestand is.
// Let op: '/index' geeft index.html, en dat is het bestand van '/'.
export function pagePath(file: string): string | undefined {
if (file === NOT_FOUND_FILE || !file.endsWith(EXTENSION)) return undefined;
const name = file.slice(0, -EXTENSION.length);
// Bestandsnamen zijn relatief aan dist/client, nooit met voorste slash
if (name === '' || name.startsWith('/')) return undefined;
return name === 'index' ? '/' : `/${name}`;
}