Routing

@tola/address:0.0.0 separates source location, logical route, output path, and public browser URL so subpath deployments and modules compose cleanly.

Path layers

Assume the site is hosted at https://example.com/docs/ (origin = "https://example.com", base-path = "/docs/"):

Route, output, and browser URL pipeline:Content sources map through routes and output-of to output paths; static assets use asset-url and pages/hook outputs use output-url to prepend base-path. Route, output, and browser URL pipeline:Content sources map through routes and output-of to output paths; static assets use asset-url and pages/hook outputs use output-url to prepend base-path.
LayerExample & role
Source path (source.path)guide/install.typ, relative to content-dir; source.file is a native path ready for include.
Route segments (source.route-segments)("guide", "install"), derived from the directory layout; transform or prefix as needed.
Site route (route)/guide/install/, leading /, decoded, without base-path.
Output path (output)guide/install/index.html, relative to publish-dir, passed to document(...) and asset(...).
Browser URL/docs/guide/install/ or https://example.com/docs/guide/install/, percent-encoded with base-path.

Route mapping

join-route builds a /.../ route from segments, output-of maps a route to an output path, and route-of reverses it:

Route passed to output-ofBundle output path
/index.html
/guide/guide/index.html
/guideguide (extensionless file)
/sitemap.xmlsitemap.xml

A trailing slash (/guide/) denotes directory page guide/index.html, whereas /guide denotes a file named guide. Keeping both content/about.typ and content/about/index.typ produces duplicate about/index.html outputs and triggers a conflict error.

Normalize casing, spaces, or apply custom permalink overrides in one shared route helper:

typst
#import "@tola/address:0.0.0": join-route, output-of, slugify

#let page-output(source) = {
  let route = if source.meta.permalink != none {
    source.meta.permalink
  } else {
    join-route(source.route-segments.map(seg => slugify(seg, language: "en")))
  }
  output-of(route)
}

When menus, neighbor links, feeds, and sitemaps all read page.output, changing a permalink keeps the entire site consistent.

Subpaths

Configure [site] in tola.toml when deploying under a subpath or emitting absolute URLs (canonical tags, RSS, sitemap):

toml
[site]
origin = "https://example.com"
base-path = "/docs/"

origin holds scheme, host, and optional port; base-path must start and end with / ("/" for domain root). Generate links in Typst through @tola/address rather than concatenating prefixes manually:

typst
#import "@tola/address:0.0.0": output-url, route-url
#import "@tola/site:0.0.0": site

#let output = "guide/install/index.html"
#let href = output-url(output)                      // "/docs/guide/install/"
#let full = output-url(output, origin: site.origin) // "https://example.com/docs/guide/install/"

#assert.eq(href, route-url("/guide/install/"))
#link(href)[Install guide]
FunctionInputBehavior
output-urlOutput path (page.output or hook output)Prepends base-path, percent-encodes, and folds index.html to /; verified after build hooks run.
route-urlDecoded site route ("/guide/install/")Prepends base-path and percent-encodes.
asset-urlDeclared [assets] URL ("/styles/site.css")Verifies immediately that the asset exists and is enabled; preserves index.html; appends ?h=<hash> when cache-busting is on.

Append #fragment after the returned URL. Raw html.a URLs are not rewritten automatically. To convert a percent-encoded request path back to an output path, strip base-path, run decode-url-path once, and pass to output-of.

Fragments

Attach a label to any native heading (= Install <install>) and link with #link(<install>)[Install] to emit the label name as the HTML id.

Path roots

  • In site files and content, / resolves to the site root.
  • In module code, / resolves to the module root. Read files from the consuming site (such as hook JSON) with project-path("generated/data.json") from @tola/site:0.0.0; include content files via source.file.
  • Module [assets] publish under /_tola-modules/<alias>/ (with base-path). Inside the module, read compile-time paths from get-module().assets.files and browser URLs from get-module().assets.urls.

See @tola/address for full signatures.

Search this site

Use the arrow keys to move through results.

Type to search.