Skip to main content
Parts of the SSG Helper are experimental. The API may change in future versions.
The SSG (Static Site Generation) Helper enables pre-rendering of Hono applications to static files, allowing you to generate static HTML, CSS, JSON, and other assets at build time.

Import

Functions

toSSG()

Generates static files from a Hono application.
Hono
required
The Hono application instance to generate static files from
FileSystemModule
required
File system module with writeFile and mkdir methods (e.g., Node.js fs/promises)
ToSSGOptions
Configuration options for static generation
Promise<ToSSGResult>
Result object containing:
  • success: boolean indicating if generation succeeded
  • files: array of generated file paths
  • error: Error object if generation failed
Example

ssgParams()

Middleware to define parameters for dynamic routes during SSG.
SSGParams | Function
required
Either an array of parameter objects or a function that returns them
MiddlewareHandler
Middleware that provides parameters for static generation
Example

isSSGContext()

Checks if the current request is running in SSG context.
Context
required
The Hono context object
boolean
true if running in SSG context, false otherwise
Example

disableSSG()

Middleware to prevent a route from being statically generated.
MiddlewareHandler
Middleware that disables SSG for the route
Example

onlySSG()

Middleware to make a route only available during SSG (returns 404 at runtime).
MiddlewareHandler
Middleware that makes the route SSG-only
Example

fetchRoutesContent()

Generator function that fetches content for all routes.
Hono
required
The Hono application instance
BeforeRequestHook
Hook called before each request
AfterResponseHook
Hook called after each response
number
Number of concurrent requests (default: 2)
Generator
Generator yielding Promises that resolve to route content

saveContentToFile()

Saves content to a file.
Promise<object>
required
Promise resolving to content data
FileSystemModule
required
File system module
string
required
Output directory path
Record<string, string>
Custom MIME type to file extension mapping
Promise<string | undefined>
Path to the saved file, or undefined if save was skipped

Types

ToSSGOptions

ToSSGResult

SSGParams

FileSystemModule

Advanced Usage

Custom Extension Mapping

Build Script Example

Dynamic Routes with Database

File Output

Generated files follow these patterns:
  • //index.html
  • /about/about.html
  • /about//about/index.html
  • /api/data/api/data.json (for JSON responses)
  • /feed.xml/feed.xml