2. The tree
astwerk's entire build mechanism is one function that walks a tree. You describe the output directory as Go values — one ssg.Node per directory — and call ssg.Build. The tree root is the site root; Page renders its index.html.
The tree is the site — here it is live; toggle the nodes the next steps add:
The tree is the site — toggle the nodes the next steps add:
build/ └── index.html
package main
import (
"log"
"github.com/LukasDerBaum42/astwerk/ssg"
"example.com/mysite/pages"
)
func main() {
root := ssg.Node{
Title: "My Site",
Page: ssg.Templ(pages.Home),
}
if err := ssg.Build(root, ssg.BuildOptions{}); err != nil {
log.Fatal(err)
}
}ssg.Templ adapts a templ component with the (title, path, prefix) signature, and the walker fills the values in — so a page never has to be told where it lives. The first page, pages/home.templ:
package pages
templ Home(title string, path string, prefix string) {
<h1>My Site</h1>
<p>A portfolio built with astwerk.</p>
}Generate the Go and build:
templ generate
go run .That writes build/index.html — whatever the component renders, verbatim. There is no scanner and no config; the tree is the site.
What is a Node?
ssg.Node describes one output directory — Title, Page, Children and the rest — and ssg.Build walks the tree and writes it.
Where does ssg.Templ get a page's path and prefix?
ssg.Templ adapts the (title, path, prefix) signature; the walker knows each page's path and locale and supplies those — you give only the title.