Gather information from documents

I’m trying to create a static site generator with typst. For each page, right now I do something akin to

#import "../lib.typ": page
#show: page(
  title: "Hello",
  description: "Hello world",
  ...
  draft: true,
)

I can set some of these fields with set document.title = ... or similar, but not all.
How would I get the data out when I generate my page?
Right now I thought of having a global state that I get after I make the page with a document(...), but I can’t really get it to work well because I don’t fully understand how context works

I believe context itself is not so complicated. It’s just that Context - Typst Documentation focuses its usage on style chains and state/counter, but sometimes people only want to pass information across the document (or bundle).

Fortunately, for passing information, metadata and query are available. And they might be easier than you thought.
Refer to Metadata - Typst Documentation for a minimal example, and Metadata - Typst Examples Book for a step-by-step tutorial.

1 Like