static

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package static implements static-site generation for a framework.App with a UIHost mounted on it. The Builder walks every registered route, runs the screen's Load(ctx) hook, renders to HTML, and writes the result to disk along with the runtime.js, compiled actions, and any static assets.

Dynamic routes (paths containing ":param" segments) participate when the screen's component implements core-ui/app.StaticPathsProvider; the builder expands the pattern against each returned param map.

Build output is suitable for any static host (S3, GitHub Pages, Cloudflare Pages, etc.). The runtime.js included alongside the HTML drives client-side navigation, form actions, and signal-driven updates after first paint, so behavior matches the SSR server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// Host is the UIHost to render through. Must already have its screens,
	// actions, and static assets configured.
	Host *uihost.UIHost
	// OutDir is the destination directory; existing contents are overwritten.
	OutDir string
	// Logger receives one line per produced or copied file. Nil disables it.
	Logger func(format string, args ...any)
}

Builder generates a static-site snapshot from a UIHost.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) (Result, error)

Build renders every reachable route to HTML and copies runtime/actions/static assets into b.OutDir. Returns a Result that lists what was produced.

func (*Builder) Watch

func (b *Builder) Watch(ctx context.Context, watchDirs []string, interval time.Duration, onError func(error)) error

Watch invokes b.Build whenever a file under any of watchDirs changes its modification time, using a polling loop with the given interval. It runs one initial build immediately and returns when ctx is cancelled.

The loop ignores errors so a transient compile-time mistake in user code (e.g. a half-saved file) does not stop watching; the most recent error is passed to onError if non-nil. If interval is <= 0 it defaults to 500ms.

Polling avoids a third-party fsnotify dependency. For projects with a large source tree this is fine — we only stat files we already know about.

type Result

type Result struct {
	Pages  []string // route paths rendered (post-expansion for dynamic routes)
	Assets []string // static asset paths copied
}

Result is a summary of a Build run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL