Content builders are how you set up custom pagetypes or override the rendering of existing pagetypes. It's the starting point to handle any request (whether static or dynamic) in a TypeScript-based WebHare site. Content builders are registered using onRenderContent in site profiles.

A content builder supplies the body and any additional metadata to a page builder which will wrap the content in a webdesign. The builder functions as a router and may skip page generation if necessary (eg. to provide a download, error page or redirection).

A custom page type with dynamic contents (ie affected by the user requesting the page) is defined in a siteprofile:

types:
  pages.signup:
    metaType: page
    dynamicExecution:
      onRenderContent: signup.ts#buildSignupPage

A stub contentBuilder implementation would look like this:

import type { ContentPageRequest, WebResponse } from "@webhare/router";
import { litty } from "@webhare/litty";

export async function renderRagTestPage(req: ContentPageRequest): Promise<WebResponse> {
  const result = litty`<p>My dynamic page</p>`;
  return req.buildWebPage(result);
}