2. A book site and its table of contents
Group pages into a site, pick the :book template, and wire the sidebar with toc.
After this lesson you can
- Declare a site and join pages to it via sites - Select a template with default_template - Build a nested sidebar with toc chapters and mark the start page
Before you start: Your first page
A site block configures one output target: its template, title, theme, and navigation. Each page joins one or more sites through its sites field, and cross-page links are markdown-style — [text](page_name) — validated at build time, so a renamed page can't silently break navigation.
The :book template reads a toc block off the site: chapters nest to any depth, a chapter without page = is a grouping heading, and a chapter pointing at an unknown page is a build error.
§ 1Exercise: A two-page book
Turn your document into a :book site with a nested table of contents and a link between the pages.
import <wdoc.wcl>
site docs {
default_template = :book
title = "Project Docs"
toc {
chapter "Intro" { page = index }
chapter "Guide" {
chapter "Setup" { page = setup }
}
}
}
page index { sites = [:docs] start = true
h1 "Project docs"
p "Start with the [setup guide](setup)."
}
page setup { sites = [:docs]
h1 "Setup"
p "Back to the [intro](index)."
}
Expected result
The build renders a fixed left sidebar with an Intro chapter and a Guide group containing Setup, and the in-page links navigate between the two pages.
Hint
If the build fails with an unknown-page error, the toc or a link names a page id that doesn't exist — page ids, not titles, are the link targets.