Static sites
A static Soda site renders every page at build time, into files any host serves: Vercel, Netlify,
GitHub Pages, a bucket. Pages are written as on any backend: routes as folders, view!,
components, layouts, typed links. sodakit.dev is one, built from this repository's docs/.
This walks through the template, Atlas: a home page, a guide and notes, all from Markdown.
Make a site#
&& field-guide/
pages/
guide/ one Markdown file per page, in file-name order
notes/ one file per note, named for its day: 2026-10-14-dark-mode.md
src/
main.rs soda_static::app!(site::Site)
site.rs loads the guide and notes from pages/
components.rs shared components
routes/
layout.rs wraps every page
page.rs /
guide/page.rs /guide
guide/[topic]/page.rs /guide/:topic
notes/page.rs /notes
notes/[note]/page.rs /notes/:note
not_found.rs built as 404.html
web/
app.html the page shell
app.css the design tokens, light and dark
tests/e2e.mjs end-to-end tests on the built siteLoad the site's data#
The site's state implements soda_static::App. Its load runs once at build time, from the
site's folder. An error stops the build and says why.
WATCH lists what load reads. Under soda dev, saving a file there reloads the data and
re-renders every open page.
Pages read it as cx.state. Name it in src/main.rs:
app!;Write a page#
// src/routes/notes/page.rs
head is written into the page's file: the title goes in <title> (as Notes · Atlas) and
og:title, the description in <meta name="description"> and og:description. Search engines and
link previews see them without running anything.
What a search engine or an assistant should know about what's on a page, in schema.org's words (a
local business and where it works, a person, an article and its day), goes in the page as
structured data: {soda::view::structured_data(&json!({"@context": "https://schema.org", "@type": "BlogPosting", "headline": …}))}, anywhere in its view (a layout's, for what every page should
say). It's written as JSON-LD, which browsers never run. A view can't hold a <script> itself, so
this is the way in, and it can't be ended early by what's in it.
A page for each item#
A route with a param, like notes/[note], lists the pages to build with params:
// src/routes/notes/[note]/page.rs
use Params;
use crate*;
- A route with a param but no
paramsis a compile error. paramscan beasync.- Link to a page with its function:
link::notes::note("dark-mode"). - A param can't be named
page. That's why the guide's is[topic].
Build#
In dist/ | What |
|---|---|
index.html | / |
guide/start-here/index.html, … | each page, in its own folder |
404.html | not_found.rs, served by static hosts for unknown addresses |
app.css, soda.js, … | styles and scripts |
sitemap.xml, robots.txt | written when the site has a url |
The build fails, listing each address, if a page errors or returns NotFound for params it was
given. A route with an #[action] is a compile error: nothing can post to files. When a site needs
actions, move its pages to a server or local-first app.
Give the site's address to get sitemap.xml and robots.txt. Each page's canonical address is
filled in too, but only where web/app.html has the tags (<link rel="canonical">,
<meta property="og:url">). Atlas's shell has neither, so add them for canonical links:
app!;A download is built once, into a file at its address, so it takes only cx:
// src/routes/downloads.rs
Link to it with href=Search. The build writes it to dist/api/_/search.
Each page and stylesheet asks for the site's images, fonts and media by version: the build adds
each file's content hash to every address that names it (src, srcset, href, poster, and
url(…) in a style or a stylesheet), so /images/meg.webp is written /images/meg.webp?v=3fa94c1e.
The template's vercel.json has browsers keep any address with ?v= for a year, so a page
that's reloaded or gone back to has its images in its first paint instead of waiting on the host,
and a file that changes is at a new address. What a script asks for, and a script or stylesheet
itself, is left as it is.
Don't give a photo that might be on the first screen decoding="async": it lets the browser paint
the page before the photo's decoded, so even a photo it kept blinks in on every reload. Leave
decoding out (or sync), and keep loading="lazy" for what's further down.
In the browser#
Each page is a file, so links and Back are the browser's own. Add a crossfade between pages with one line of CSS (the template has it):
@ }A page renders the same for everyone, from its path alone. The query string and cx.recall aren't
available, and cx.now() is the build time.
soda dev#
soda dev runs the site as a server, rendering each page when it's requested, exactly as the
build would. Code changes are patched in and open pages re-render in about 0.6 s. Saving a watched
file shows at once. A page that panics shows the error in its place.
Test#
soda check runs the site's tests (cargo test), Clippy and the token check. soda test then
builds the site and runs tests/e2e.mjs in real browsers against dist/, served as a static host
serves it. It checks each page's head, the links, the 404, and that no page asks for a backend.
Deploy#
dist/ works on any host that serves files.
soda deploy publishes with Vercel. It needs the Vercel CLI (npm i -g vercel), linked to the
site's project (vercel link). It runs scripts/build.sh locally as vercel.json says, then
uploads dist/ with vercel.json's headers (including its Content-Security-Policy). A static
site's policy keeps 'unsafe-eval' for Datastar's expressions: the server and local-first
backends give each page a nonce of its own instead, but a nonce written into a built file would be
everyone's, and nothing on a static page comes from anyone but the site.
To build on the host instead (a Vercel or Netlify project connected to the repository, or CI):
- Depend on the SDK by its repository, not a path, so
Cargo.lockpins the commit. The template'sCargo.tomlshows how. - Run
scripts/vercel-install.sh, thenscripts/build.sh. The SDK's repository is private, so setSODA_SDK_TOKEN(a read-only GitHub token for it) in the host's project. - Serve
dist/.
This page is docs/static.md in the SDK, built into this site as it is.