ARKlight logoARKlight
Getting startedTutorialReferenceExamplesWhyChangelog

Tutorial

Tutorial overview
1. Pages and routes
2. State and actions
3. Styling and layout
4. Reusable components
5. Lists and conditionals

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

/404

route 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.

Next: the

reference

covers every component and action in the vocabulary.

Previous: Tutorial overviewNext: 2. State and actions
LicenseChangelogGitHubPyPI

ARKlight is GPLv3 with attribution terms; sites you build are yours. Your browser is still running JavaScript. We just made Python responsible for getting it there.