Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Static Website

lat new scaffolds a static website as a theme folder: pages, layouts, partials, content and assets, with no database and no Rust project.

lat new "Acme" --static
cd acme
lat serve          # http://127.0.0.1:8080, rebuilt on every change
lat theme build    # dist/

lat new without --static asks first:

PromptValue
What are you building?An application with an admin panel, or a static website.
Where does the site’s content live?In this folder as files you edit (--content files, what --static alone means); in this folder, edited in the admin (folder); in this folder, committed by the admin (git); in a database with the admin beside it (database).
Application nameAny text; its slug names the folder and the theme.
Site URLThe origin canonical links use.
Database, Build hook URLFor database: the connection, and the host’s hook (blank to set later).
First administratorFor every choice but files: username, email, password.
lat new "Acme" --static --content git
cd acme
lat serve                     # the admin at http://127.0.0.1:8080/admin, the site beside it
lat make:resource article --field title:text --source content/articles --format markdown --git
git remote add origin git@github.com:acme/site.git
lat theme publish             # push the commits the admin made
lat theme build               # dist/, as the host does on push

A site whose content is edited in the admin is an application whose build is static: it carries the Cargo project, src/main.rs with the theme module, the framework’s own tables in storage/site.db (or the database named), and the theme folder. A folder or git site also carries its first plugin, plugins/site-plugin, with a post collection kept as records in files under content/posts/, the posts component the theme reads it through, and the pages /posts and /posts/:slug built per record. Folders named in theme.copy are served by lat serve as the build copies them. lat serve runs its admin; lat theme build renders dist/; lat theme publish pushes (git) or calls the build hook (database). Default https://<slug>.example.

See what it generates

acme/
├── config/default.toml        # [app] name, url; [theme] folder, copy
├── themes/acme/
│   ├── theme.yaml
│   ├── layouts/default.htm
│   ├── pages/home.htm         # url: /
│   ├── pages/about.htm        # url: /about
│   ├── pages/404.htm
│   ├── partials/nav.htm
│   ├── content/intro.md
│   └── assets/css/site.css
├── build.sh                   # installs lat, runs the build
├── netlify.toml
└── README.md

A page carries its settings as front matter above the markup:

---
url: /about
layout: default
title: About
description: Who we are and what we do.
---
<h1>{{ this.page.title }}</h1>
<p>{{ this.page.description }}</p>

The settings and the template language are those of a theme in an application: Pages, Layouts and Partials, Content, Templating.

Set the config

[app]
name = "Acme"
url = "https://acme.example"

[server]
listen = "127.0.0.1:8080"

[theme]
folder = "themes/acme"
copy = ["static:static"]
KeyDefaultMeaning
app.urlThe origin canonical links use.
server.listen127.0.0.1:8080The preview’s address.
theme.folderThe theme folder, relative to the project; its name is the theme’s code.
theme.copy[]Directories copied into the output, <src>:<dest>, relative to the project. A source absent on this machine is skipped with a note; a --copy flag’s is required.

Preview

lat serve
lat serve --port 3000
lat theme serve --from themes/other

Every request rebuilds the site when a file under the folder changed; a template that does not compile shows its error in the browser.

Build and deploy

lat theme build
lat theme build --out public --base-url https://acme.example
lat theme build --from themes/other --copy docs/book:docs
FlagDefaultMeaning
--from <DIR>theme.folderThe theme folder.
--out <DIR>distThe output directory.
--base-url <URL>app.urlThe origin canonical links use.
--copy <SRC>:<DEST>theme.copyA directory copied into the output at <DEST>. Repeatable, added to the config’s.

build.sh runs the same build on a host that starts from nothing:

cargo install laterite-cli --locked
lat theme build --out dist

netlify.toml points Netlify at it and serves dist/.

Choose where the content lives

[theme]
folder = "themes/acme"
source = "folder"
SourceThe theme isEditedPublished
databasethe rows in [database]in the adminlat theme publish calls theme.publish.hook
folderthe theme folderin your editor, or in the admin, which writes the filescommit the folder
gitthe theme folderin the admin, which commits every savelat theme publish pushes
a module’sits ownits ownits own

folder and database are always available; git needs the theme-git feature:

lateritecmf = { version = "0.12", features = ["sqlite", "theme-git"] }
[theme]
folder = "themes/acme"
source = "git"

[theme.git]
remote = "origin"
branch = "main"

[theme.publish]
hook = "https://api.netlify.com/build_hooks/..."
KeyDefaultMeaning
theme.sourcedatabaseThe source by code.
theme.git.remote, theme.git.branchorigin, mainWhere publish pushes.
theme.publish.hooknoneA URL lat theme publish posts to after the source published; the host rebuilds on it.

A file-backed source is read in before every build, and every save in the admin is written back. The framework’s own tables (users, sessions, settings, logs) stay in [database].

Keep media with the site

[media]
folder = "public/media"

Uploads land in the folder, a git site commits each one, and the build writes every file and its variants under dist/storage/media/. See Admin configuration.

Edit from a laptop

cargo build --release
./target/release/acme admin

admin serves the application and opens the admin in the browser. With a folder or git source and records in files, every save lands in the checked-out repository; push it to publish.

CommandDoes
acme or acme serveServes the admin and the site on server.listen.
acme adminThe same, and opens /admin in the browser.
acme buildRenders dist/.
acme publishPushes, or calls the build hook.

Add a plugin

lat plugin add https://github.com/rainmill/discovery-plugin
lat new "Acme" --static --plugin ../discovery-plugin

The first plugin gives the site a Cargo project (Cargo.toml, src/main.rs, plugins/); lat serve and lat theme build run that binary from then on, and the plugin takes part in the build. A plugin a static website can use declares it in its manifest:

[package.metadata.laterite]
plugin = "rainmill.discovery"
static = true

A plugin without static = true is refused at install; one whose module answers supports_static false stops the build, by name. A plugin’s definitions live under plugins/<module id>/:

acme/
├── plugins/
│   ├── plugins.toml
│   └── rainmill.discovery/
│       ├── robots.yaml
│       └── sitemap.yaml
├── src/main.rs
└── Cargo.toml
# plugins/rainmill.discovery/robots.yaml
groups:
  - agents: ["*"]
    disallow: ["/drafts/"]

What each plugin reads is on its own page; the discovery plugin writes robots.txt and a sitemap.xml of every page the build wrote.

Move to an application

cd themes && zip -r ../acme.zip acme && cd ..
lat new "Acme"
cd acme && lat theme import acme ../acme.zip

The folder is the theme’s export layout: the same files become the application’s theme. See Export and Import.