Typst Support - Reading Metadata
Shiroa emits labeled metadata from book.typbook.typ. The query helpers below read the final values during page, theme, and ebook compilation.
Queries the final book metadata. It is context-dependent; use its mappermapper argument when a theme needs a value from the metadata.
#import "@preview/shiroa:0.4.0": get-book-meta#let site-title() = get-book-meta(mapper: meta => { if type(meta) == array { meta = meta.first() } if meta == none { "" } else if "raw-title" in meta { if meta.raw-title == none { "" } else { meta.raw-title } } else if "title" in meta and type(meta.title) == str { meta.title } else if "title" in meta { meta.title.content } else { "" }})#context site-title()
#import "@preview/shiroa:0.4.0": get-book-meta#let site-title() = get-book-meta(mapper: meta => { if type(meta) == array { meta = meta.first() } if meta == none { "" } else if "raw-title" in meta { if meta.raw-title == none { "" } else { meta.raw-title } } else if "title" in meta and type(meta.title) == str { meta.title } else if "title" in meta { meta.title.content } else { "" }})#context site-title()
The mapper receives nonenone when no book metadata is available, one dictionary for a normal book, or an array if multiple matching metadata values exist.
#import "@preview/shiroa:0.4.0": get-build-meta#let destination() = get-build-meta(mapper: meta => { if type(meta) == array { meta = meta.first() } if meta == none { "" } else { meta.at("dest-dir", default: "") }})#context destination()
#import "@preview/shiroa:0.4.0": get-build-meta#let destination() = get-build-meta(mapper: meta => { if type(meta) == array { meta = meta.first() } if meta == none { "" } else { meta.at("dest-dir", default: "") }})#context destination()
The equivalent query helper for build metadata. It follows the same contextual and mappermapper behavior as get-book-metaget-book-meta.
A statestate updated by book-metabook-meta. The bundled ebook template reads its final value while traversing an externally included book. Site themes should use get-book-metaget-book-meta, which queries the labeled final metadata and handles normal chapter compilation.