@tola/source

Discover Typst content files, inspect the current source, and declare or validate page metadata.

Import

typst
#import "@tola/source:0.0.0": *

The site entry decides which discovered sources become pages and defines the meaning of site-specific metadata fields such as title, draft, or permalink.

Exports

all-sources

typc
let all-sources() = array;

List all Typst content files under build.content-dir, sorted by relative path.

Discovers files ending in lowercase .typ under build.content-dir, skipping hidden names, symlinks, and the site entry file. Sort the returned array yourself when ordering by date or metadata.

Record fieldMeaning
id, pathPath relative to build.content-dir including .typ (for example "posts/deep.typ"). Both change when a file is moved or renamed; store a fixed id in metadata for stable feed entries.
fileTypst path rooted at the site directory; pass directly to include or read.
filenameFinal path segment (for example "deep.typ").
route-segmentsDefault route segments derived from the path (() for home, ("about",) for both about.typ and about/index.typ).
metaMetadata dictionary declared by tola-meta, collected across pages in site.typ.

Run tola inspect sources to list discovered files without evaluating metadata, or tola query to export metadata as JSON.

current-source

typc
let current-source() = dictionary;

Return (id, file, path, filename, route-segments) for the content source containing this call.

Callable outside context. Call it inside an article and pass the result to your template—calling it directly inside a template outside build.content-dir raises an error. To look up where an article is published, use @tola/document#current-document.

tola-meta

typc
let tola-meta(
  payload: dictionary,
) = content;

Declare the metadata dictionary for the current content source file.

Call at most once per content file, directly near the top of the file or via an imported helper wrapper. Calls deferred inside context or selector show rules do not declare source metadata, and a top-level #show: runs after the body (so a body error can prevent it from executing). Syntax or runtime errors in any discovered file fail the build even if your site entry later filters that file out as a draft.

Returns an invisible <tola-meta> metadata marker queryable with query(<tola-meta>), though recording happens at call time regardless of whether the return value is inserted into content.

Positional parameters

  • payload dictionary required: Dictionary of metadata fields for this content file.

Wrap `tola-meta` in a typed helper

typst
#import "@tola/source:0.0.0": tola-meta

#let post(..fields) = tola-meta(fields.named())

parse-sources

typc
let parse-sources(
  sources: array,
  schema: type | dictionary | function,
) = array;

Validate source records with a @tola/schema rule and return records with parsed meta values.

Sources without a tola-meta call are validated as empty dictionaries. Returned records preserve input order and paths; validation failures point diagnostics directly to the offending source file and metadata span.

Positional parameters

  • sources array required: Array of source records from all-sources() or a filtered subset.
  • schema type | dictionary | function required: A @tola/schema declaration, or a function (source) => schema selecting a schema per source record.

Validate metadata, filter drafts, and publish pages

typst
#import "@tola/address:0.0.0": join-route, output-of, slugify
#import "@tola/schema:0.0.0": non-empty, optional, schema, trim
#import "@tola/source:0.0.0": all-sources, parse-sources

#let page-schema = schema((
  title: non-empty(trim(str)),
  draft: optional(bool, default: false),
), unknown: "keep")

#let pages = parse-sources(all-sources(), page-schema).filter(s => not s.meta.draft)
#for page in pages {
  let output = output-of(join-route(page.route-segments.map(slugify)))
  document(output, format: "html", title: page.meta.title)[#include page.file]
}

Search this site

Use the arrow keys to move through results.

Type to search.