Askr
Rendering

Static Site Generation

Use static site generation with the current published Askr packages.

  • @askrjs/askr/ssg0.0.59
  • @askrjs/cli0.0.5

How to use static site generation

Export the route registry, document renderer, and assets from ssg.config.ts, then let the CLI enumerate every registered static route.

  1. Import the published @askrjs/askr/ssg and @askrjs/cli entrypoint.
  2. Keep static site generation configuration next to the component, route, or server composition root that owns it.
  3. Handle pending, unavailable, cancellation, and failure states, then verify the production path.
export const staticConfig = {
  registry,
  outputDir: 'dist',
  document: renderDocument,
  assets: [{ from: resolve('public'), to: '.' }],
};

// askr ssg --config ./ssg.config.ts --output ./dist

Static registry

`createStaticGen` from `@askrjs/askr/ssg` takes either a `routes` array of `RouteConfig` entries or a `registry: RouteRegistry` captured with `createRouteRegistry()` — the same registry shape used by SSR and boot. Each `RouteConfig` has a `path`, a `handler` (or the legacy `component` alias), optional `props`, and an `entries()` function for parameterized paths like `/posts/{slug}` that returns one param map per page to generate.

Document rendering

`SSGOptions` accepts the same `document: DocumentRenderer` used by SSR, plus a `seed` for deterministic output and `dataOverrides` keyed by route for supplying resource data without a live backend. Calling `.generate(options)` renders every configured route and returns an `SSGResult` with per-route status (`success`, `error`, `skipped`, `removed`) and the reason each route was or wasn't rebuilt — useful for `SSGMode: 'incremental'` runs driven by `changedKeys` or `changedRoutes`.

Assets and output

`outputDir` is where generated HTML and `metadata.json` land; `assets: readonly SSGAssetSource[]` lets you copy additional files or directories in alongside them, each with a `from` source and an optional `to` destination relative to `outputDir`. The CLI wraps this as `askr ssg --config <path> --output <dir> [--incremental]` so a build script doesn't need to call `createStaticGen` directly.

404 and hosting

There's no dedicated 404 API in `@askrjs/askr/ssg` — a not-found page is just another `RouteConfig` entry you generate to a path like `/404`, and your static host is responsible for serving it as the fallback for unmatched paths (most static hosts look for `404.html` or a configured error-document setting). Routes with `auth` requirements or runtime-only `policies` are excluded from prerendering by default, since SSG can't evaluate a per-request auth check at build time.