Pages and routes
Every ARKlight site is a Site plus one decorated function per page.
The shape of a site
# include <stdlib.ARKlight>
site = Site()
@site.page("/")
def home():
return Page(
Heading("Home"),
Text("Welcome."),
title="Home",
)
@site.page("/about")
def about():
return Page(
Heading("About"),
Link("Back home", href="/"),
title="About",
)Positional arguments to any component are its children. Keyword arguments are props, such as
title=on
Page.
Why the include line matters
# include <stdlib.ARKlight>looks like a comment to Python, but to ARKlight it is a compiler directive that brings the built-in vocabulary into scope. Leave it out and you get
name 'Site' is not defined, with no hint that a directive is missing. Every file ARKlight loads needs its own include line.
How routes are found
ARKlight parses your entry file as an AST to find routes, and does not run it to discover them. That means it looks for specific syntax shapes. Use the literal decorator form
@site.page("/path"), in the file you pass to
arklight build.
Calling
site.page("/")(home)is valid Python, but ARKlight silently ignores it and fails with
No pages registered on 'site'. See
gotchas.
Where each route becomes a file
/builds to
index.html. Other routes build to their own HTML files. A
/404route builds to
404.html, which static hosts such as GitHub Pages serve for missing pages.
Try it
- Add a third page and link to it from the other two.
- Move the page bodies into helper functions in another module, keeping every @site.page in the entry file.
