Authoring modules
Modules declare capabilities opt-in inside tola-module.toml; each entry point works independently:
| Manifest table | Role |
|---|---|
[typst] | entry exports the public Typst library (@tola-modules/<alias>:0.0.0); fonts adds compiler font folders. |
[build] | entry supplies a full-site build entry selected via build.entry = { module = "<alias>" }. |
[nu] | entry exports a public Nu library (use tola-modules <alias> or tola nu @tola-modules/<alias>). |
[options] / [assets] / [icons] | Declares option defaults, module static assets (supporting enabled-by), and module icon sets. |
[queries] | Registers named tola query <alias>.<name> queries and powers LSP completion, hover, go-to-definition, and rename. |
[commands] | Registers tola <alias> <command> subcommands backed by nu, argv, query, or skill. |
[init] | Registers a site initializer invoked by tola init <dir> --from <source> --alias <alias>. |
[pack] / [[hooks.before-pack]] | Declares pre-release asset compilation and package allowlists for tola module pack. |
Minimal theme
A manifest and lib.typ make a component library; adding site.typ, [options], and [assets] turns it into a full theme:
[typst]
entry = "lib.typ"
[build]
entry = "site.typ"
[options]
show-title = true
extra-styles = []
[assets]
files = [{ source = "assets/theme.css", url = "/theme.css" }]#import "@tola/address:0.0.0": asset-url, join-route, output-of
#import "@tola/module:0.0.0": get-module
#import "@tola/schema:0.0.0" as s
#import "@tola/site:0.0.0": site
#import "@tola/source:0.0.0": all-sources, parse-sources, tola-meta
#let note(..fields) = tola-meta(fields.named())
#let page-schema = s.schema((title: str, draft: s.optional(bool, default: false)))
#let pages() = {
parse-sources(all-sources(), page-schema)
.filter(source => not source.meta.draft)
.map(source => (source: source, output: output-of(join-route(source.route-segments))))
}
#let article(source) = [
#if get-module().options.show-title { title(source.meta.title) }
#include source.file
]
#let render-site(article: article) = {
let mod = get-module()
set text(
lang: site.language.lang,
script: site.language.script,
region: site.language.region,
)
for page in pages() {
document(page.output, format: "html", title: page.source.meta.title)[
#html.html(lang: site.language.tag)[
#html.head[
#html.meta(charset: "utf-8")
#html.meta(name: "viewport", content: "width=device-width, initial-scale=1")
#html.title(page.source.meta.title)
#html.link(rel: "stylesheet", href: mod.assets.urls.at("theme.css"))
#for url in mod.options.extra-styles {
html.link(rel: "stylesheet", href: asset-url(url))
}
]
#html.body[
#html.main(class: "page", article(page.source))
]
]
]
}
}#import "lib.typ": render-site
#render-site()Run tola module check ./theme to verify manifest declarations, then mount the theme in a real test site to inspect output.
Options & assets
Manifest option bindings
In tola-module.toml, hook fields (dev, order, rerun-on, args, generates, outputs), asset fields (minify, include, exclude), and command fields (args, projection) can bind to merged options using { option = "..." }:
[options.search]
enabled = true
dev = "skip"
[[hooks.generate-outputs]]
name = "search"
enabled-by = "search.enabled"
dev = { option = "search.dev" }
nu = "tools/search.nu"
outputs = [{ tree = "_tola-modules/{name}/search" }]Module paths
Module [assets] resolve relative to the module root and publish under /_tola-modules/<alias>/. Keys in get-module().assets.urls omit the leading slash (such as "theme.css"). Individual assets support enabled-by (even when false by default, include the source file when packing).
Inside module Typst code, / points to the module root; read files from the site project (such as hook JSON outputs) via project-path("generated/...") from @tola/site.
Fonts & icons
Ship compiler fonts via [typst] fonts = ["typst-fonts"] (enabled in sites via [typst.fonts].modules). Declare module icon collections under [icons.collections] and bind them to the active instance with icon.with(module: get-module().name).
Named queries
Register named queries under [queries.<name>] reusing pages() from lib.typ so queries and builds see identical pages:
[queries.index]
entry = "queries/index.typ"
label = "page-index"
[[queries.index.references]]
export = "page-link"
parameter = { positional = 0 }
[[queries.index.definitions]]
export = "page"
parameter = { named = "id" }// theme/queries/index.typ
#import "../lib.typ": pages
#import "@tola/address:0.0.0": output-url
#metadata(pages().map(p => (
id: p.source.id,
name: p.source.meta.title,
source: p.source.file,
url: output-url(p.output),
))) <page-index>When a query produces an array of records with fields id (unique non-empty string), name (string), and optional description, source (native path), and url, declaring references and definitions gives tola lsp completion, hover docs, go-to-definition, and rename for those exported function arguments.
Commands
[commands.<name>] accepts nu, argv, query, or skill, invoked as tola <alias> <name>:
[commands.setup]
argv = ["npm", "--prefix", "{module}", "ci"]
help = "Install the theme's Node.js dependencies"
[commands.pages]
query = "index"
projection = ["id", "name", "url"]
[commands.guide]
skill = "README.md"
help = "Read the theme authoring guide"nu and argv commands execute in the site root with args prepended before user arguments, expanding {module}, {project}, and {tola}. skill commands share --list, --all, and -o flags with tola skill.
Site initializer
Declare [init] nu = "tools/init.nu" so users can scaffold a site with tola init my-site --from <source> --alias notes [-- extra args] (or tola notes init new-site inside an existing workspace):
use tola get-init
def main [] {
let init = get-init
{
build: {entry: {module: $init.module.name}}
modules: {($init.module.name): {path: $init.module.root}}
} | to toml | save --raw ($init.output-dir | path join "tola.toml")
mkdir ($init.output-dir | path join "content")
[
$'#import "@tola-modules/($init.module.name):0.0.0": note'
'#note(title: "Welcome")'
] | str join (char nl) | save --raw ($init.output-dir | path join "content" "index.typ")
}Write all generated files into $init.output-dir (a staging directory safe for --dry-run), using $init.target-dir only to compute relative paths. Tola rewrites the initializer module entry to preserve the user’s path, Git selector, or tarball URL and locks remote dependencies into tola.lock. get-site and get-module are unavailable during init; inspect $init.interactive before prompting.
Packing & release
When a module ships precompiled frontend assets, run compilation in [[hooks.before-pack]] and list deliverables in [pack]:
[pack]
include = ["lib.typ", "site.typ", "assets", "queries", "tools", "README.md"]
exclude = ["assets/**/*.map"]
[[hooks.before-pack]]
name = "compile-assets"
nu = "author/assets.nu"before-pack reads the module source folder via get-context | get hook.inputDir and writes built assets there. Pack, verify, and archive:
mkdir -p dist
tola module pack ./theme --output ./dist/theme
tola module check ./dist/theme
tar -czf dist/theme-v1.0.0.tar.gz -C dist themetola module pack copies tola-module.toml while stripping [pack] and before-pack so consumers do not need author build tools. Archives must preserve one outer folder containing tola-module.toml. Because GitHub auto-generated source tarballs skip before-pack, attach packed archives to GitHub Releases or commit the packed directory for git.subdir.
Before releasing, test the packed module in a standalone site under a renamed alias, custom options, and a non-root base-path, running tola check and tola preview without author tools installed.