smalldocs.serve

smalldocs preview: build the site, serve it on localhost, and rebuild and reload the browser on every change.

snapshot

source

snapshot(root: Path, out: Path) -> dict[str, float]

Note the modification time of every source file.

Parameter Type Default Description
root Path required The project folder
out Path required The output folder, which is left out
returns dict[str, float] Each file’s modification time

class Handler

source

Serve the output folder, and the build number at /__smalldocs__/version.

Handler.do_GET

source

Handler.do_GET() -> None

Answer the build number, or a file.

Handler.end_headers

source

Handler.end_headers() -> None

Ask the browser not to cache, so a reload shows the new build.

Handler.log_message

source

Handler.log_message(format: str, *args: object) -> None

Print nothing for each request.

Parameter Type Default Description
format str required The message, with % fields
args object required The values for the fields

rebuild

source

rebuild(root: Path) -> Path | None

Build the site for preview, printing a failure instead of stopping.

Parameter Type Default Description
root Path required The project folder
returns Path | None The output folder, or None when the build failed

preview

source

preview(root: Path, host: str = '127.0.0.1', port: int = 4200, open_browser: bool = True) -> int

Build, serve and watch until stopped with Ctrl-C.

Parameter Type Default Description
root Path required The project folder
host str '127.0.0.1' The address to listen on
port int 4200 The port
open_browser bool True Open the site in a browser
returns int The exit code