Functions
f
asset(path: string): string
Returns the path of a hashed file name, or the input path if not found in generatedAssets.json
f
css( strings: TemplateStringsArray, ...values: Array<string | number>
f
findFiles(pattern: string | string[]): Promise<string[]>
Return the file paths on the local file system, relative to the current working directory,
expanding glob patterns like * and **. Do not pass it untrusted input.
f
getParams(req: Request): Record<string, string | undefined>
Take the path of a URL and extract its parameters.
See the Mastro Guide.
f
Returns the GitHub Pages base path (or an empty string).
f
html( templateParts: TemplateStringsArray, ...params: Html[]
Tagged template literal to construct Html nodes.
This makes sure things are properly escaped (unless unsafeInnerHtml is used).
f
htmlResponse( body: string | AsyncIterable<string>, status?: number, headers?: HeadersInit
Create a standard Response object with Content-Type: text/html from a string
or AsyncIterable<string> (in which case it will stream it).
f
Create a standard Response object from an Html node.
f
Returns true iff val is an async iterable
f
jsonResponse( body: object, status?: number, headers?: HeadersInit
Create a standard Response object with Content-Type: application/json.
f
readDir(path: string): Promise<string[]>
Read the directory on the local file system and return its files,
non-recursive and ignoring symlinks.
f
readFile(path: string): Promise<Uint8Array<ArrayBufferLike>>
Return the contents of a binary file on the local file system.
f
readJsonFiles<T>( pattern: string, opts?: { schema?: StandardSchemaV1<unknown, T>; }
Read all files from the local filesystem that match the supplied glob pattern, (via findFiles)
and parse then as JSON. Filepath is in path, filename without suffix in slug.
f
Return the contents of a text file on the local file system as a string.
f
renderToStream(node: Html): string | AsyncIterable<string>
Convert an Html node to a properly escaped stream.
Returns an AsyncIterable<string> if there are Promises or AsyncIterables in the input,
otherwise returns a string.
f
Convert an Html node to a properly escaped Promise<string>.
f
Convert an Html node to a properly escaped string but
throws if the input contains a Promise or AsyncIterable.
You probably want to use renderToString or renderToStream instead.
f
sseResponse<T extends object>( stream: AsyncIterable<T>, headers?: HeadersInit
Create a standard Response object to stream an AsyncIterable of JSON data as
server-sent events.
f
Mark a string as already properly escaped HTML. Do not use this on an untrusted/user-supplied string!
Type Aliases
T
Html = HtmlPrimitive | Html[] | AsyncIterable<Html> | Promise<Html>
An Html node – i.e. what can be used with html tagged templates.
T
HtmlPrimitive = String | string | number | undefined | null | false
HTML primitive values like strings and numbers.
Variables
v
File path separator. \ on Windows, / otherwise.