SSG for typst-based websites - keep your focus on the content
SSG for typst-based websites - keep your focus on the content
[ English | 中文 ]
A static site generator for Typst-based websites.
Note (v0.7.x): Released now. Some caching-related bugs may still exist. You can use
tola s -c(serve --clean) as a workaround, but please try regularservefirst so I can collect feedback and fix these issues in upcoming updates. Thanks for your support!
Yeah, my blog is also built with
tola.
| Site | Description |
|---|---|
| kawayww.com | Author's personal blog |
| example-sites | Official example collection |
My site (kawayww.com)
Starter Template (example-sites/starter)
How to make "Recent 5 Posts" with Tola's virtual package system
Thanks to typst and tailwindcss, tola offers writing flexibility.
Implement Recent Posts easily with the @tola/pages virtual package.
This snippet is aligned with the starter virtual package article source:
https://github.com/tola-rs/example-sites/blob/main/starter/content/posts/virtual-packages.typ.
#import "@tola/pages:0.0.0": pages
#import "/components/ui.typ" as ui
#let posts = (pages()
.filter(p => "/posts/" in p.permalink)
.filter(p => p.at("date", default: none) != none)
.sorted(key: p => p.date)
.rev())
#html.div(class: "space-y-6")[
#for post in posts.slice(0, calc.min(posts.len(), 5)) {
ui.post-card(post)
}
]The @tola/pages package provides access to all page metadata (title, date, permalink, tags, etc.) at compile time.
tola init gets you running in secondscontent/posts/hello.typ → /posts/hello/feed.xml from page metadatasitemap.xml for search enginesog-tags() in TypstTola injects virtual packages at compile time, enabling cross-page data access without external build steps:
@tola/site:0.0.0 — Site metadata and root path@tola/pages:0.0.0 — All pages metadata (title, date, permalink, tags, draft status...)@tola/current:0.0.0 — Current page context (current-permalink, path, headings, navigation helpers...)#import "@tola/pages:0.0.0": pages
#import "@tola/site:0.0.0": info, root
// List all posts
#for post in pages().filter(p => "/posts/" in p.permalink) {
[#post.title (#post.date)]
}
// Access site title
#info.titleCanonical examples are maintained in the starter article:
https://github.com/tola-rs/example-sites/blob/main/starter/content/posts/virtual-packages.typ
See Virtual Packages in Usage for more details.
Keep your focus on the content itself.
If Typst can easily do it, use Typst. No need to explain Typst's strengths here — even with HTML export losing many layout features, it's still remarkably powerful.
tola leverages Typst's markup and scripting capabilities instead of reinventing the wheel.
Some things are beyond what a standalone typst CLI can do — especially batch processing and site-wide coordination:
sys.inputs and virtual packages injectionThat's where tola steps in — optimizing developer experience and integrating these features seamlessly is no small feat.
Run tola --help or tola --help for detailed CLI usage.
You can run tola from any subdirectory — it will automatically find tola.toml by searching upward.
…The routing under content/ is probably intuitive — files map to URLs. But you might wonder about build.deps in tola.toml. You can actually use it without thinking too hard, but a quick explanation might help:
Typst files in content/ become pages. But they often #import shared code from templates/, utils/, or something else you prefer — these are just conventional names tola provides by default, feel free to rename them. Tola tracks these dependencies internally. When you declare directories in build.deps, tola knows: "if anything here changes, recompile all pages that import from it." This enables instant hot-reload across your entire site.
templates/ and utils/ are just default names — you can rename them or add more via build.deps. For example: you have templates/base.typ that styles math equations with Tailwind classes. When you change text-base to text-2xl in that file, any page importing it (like content/example.typ -> /example/) will instantly reflect the larger equations — no manual refresh needed.
Common tola.toml settings (run tola init --dry to see full defaults):
…Tola provides virtual packages that you can import directly in your Typst files.
Important: use the starter article as the source of truth for API names and examples. Do not maintain separate hand-written variants in multiple places.
tola-rs.github.io/example-sites/starter/posts/virtual-packages/tola-rs/example-sites/starter/content/posts/virtual-packages.typgithub.com/tola-rs/example-sites/tree/main/starter| Package | Exports |
|---|---|
@tola/site:0.0.0 |
info — Site metadata (title, author, email, description, url, language, copyright, extra); root — Site root path |
@tola/pages:0.0.0 |
pages(), by-tag(tag), by-tags(..tags), all-tags() |
@tola/current:0.0.0 |
current-permalink, parent-permalink, path, filename, links-to, linked-by, headings, siblings(pages), children(pages), breadcrumbs(pages, include-root: false), at-offset(sorted-pages, offset), prev(sorted-pages, n: 1), next(sorted-pages, n: 1), take-prev(sorted-pages, n: 1), take-next(sorted-pages, n: 1) |
// content/index.typ — list recent posts
#import "@tola/pages:0.0.0": pages
#let posts = (pages()
.filter(p => "/posts/" in p.permalink)
.filter(p => p.at("date", default: none) != none)
.sorted(key: p => p.date)
.rev())
#let recent = posts.slice(0, calc.min(posts.len(), 5))
#for post in recent {
[- #link(post.permalink)[#post.title]]
}Example: Recent Posts
#import "@tola/pages:0.0.0": pages
#let posts = (pages()
.filter(p => "/posts/" in p.permalink)
.filter(p => p.at("date", default: none) != none)
.sorted(key: p => p.date)
.rev())
#let recent = posts.slice(0, calc.min(5, posts.len()))
#for post in recent {
[- #link(post.permalink)[#post.title]]
}Example: Filename-Derived Metadata
Use path and filename from @tola/current to parse date from filename like 2025_02_27_hello.typ:
#import "@tola/current:0.0.0": path, filename
#let file = filename.replace(".typ", "").replace(".md", "")
#let parts = file.split("_")
#let auto-date = if parts.len() >= 4 {
parts.slice(0, 3).join("-")
} else {
none
}Example: Hierarchy + Navigation Helpers
#import "@tola/pages:0.0.0": pages
#import "@tola/current:0.0.0": prev, next, breadcrumbs, children, siblings
#let all = pages()
#let sorted-posts = (all
.filter(p => "/posts/" in p.permalink and p.date != none)
.sorted(key: p => p.date))
#let prev-post = prev(sorted-posts)
#let next-post = next(sorted-posts)
#let crumbs = breadcrumbs(all, include-root: true)
#let direct-children = children(all)
#let same-level = siblings(all)Example: Offset Navigation Window
#import "@tola/pages:0.0.0": pages
#import "@tola/current:0.0.0": at-offset, take-prev, take-next
#let dated = (pages()
.filter(p => "/posts/" in p.permalink and p.date != none)
.sorted(key: p => p.date))
#let two-back = at-offset(dated, -2)
#let two-forward = at-offset(dated, 2)
#let previous = take-prev(dated, n: 2)
#let next = take-next(dated, n: 2)Tola auto-injects default OG tags from [site.info] when site.seo.auto_og = true. For page-specific customization, use the og-tags() function in your template's head parameter:
#import "/templates/tola.typ": tola-page
#import "/utils/tola.typ": og-tags, parse-date
#let head = og-tags(
title: "My Post",
description: "A great article about...",
url: "https://example.com/posts/my-post/",
image: "https://example.com/og-image.png",
type: "article", // "website" | "article" | "book" | "profile"
published: parse-date("2024-01-15"), // article:published_time
tags: ("rust", "typst"), // article:tag
)
// In your template
tola-page(
title: "My Post",
head: head,
)[...]When you use og-tags(), Tola skips auto-injection and uses your custom tags instead.
# Create a new site
tola init my-blog
cd my-blog
# Edit `content/index.typ`
# Build for production
tola build
# Start development server
tola servecargo install --locked tolaDownload from the release page.
A flake.nix is provided in the repo. Pre-built binaries are available at [tola.cachix.org](https://to
No open issues yet, or sync has not completed.