[]previous and next page

outputFileFor

Maps a URL path to the file it is written to, relative to the output directory.

Maps a URL path to the file it is written to, relative to the output directory. The path is decoded and checked like a request path: no ./.. segments, no control characters or backslashes, segments up to 255 bytes, total up to 1024 characters.

Import#

ts
import { outputFileFor } from "@shadow-js/dusk/static";

Signature#

ts
function outputFileFor(
  path: string,
  format: "directory" | "file",
  contentType: string,
): string

Parameters#

Name Description
path The URL path (no query, no fragment).
format Directory or file layout for HTML pages.
contentType The page's content type; a file-like path with a non-HTML type keeps its name.

Returns#

The relative file path with / separators.

Throws#

  • PrerenderError PRERENDER_PATH_REJECTED for a path that cannot be written safely.

Examples#

ts
outputFileFor("/about", "directory", "text/html"); // "about/index.html"
outputFileFor("/feed.xml", "directory", "application/xml"); // "feed.xml"