diff options
| -rw-r--r-- | build.py | 15 | ||||
| -rw-r--r-- | site/common.typ | 24 | ||||
| -rw-r--r-- | uv.lock | 2 |
3 files changed, 34 insertions, 7 deletions
@@ -10,7 +10,7 @@ from pathlib import Path import jinja2 from loguru import logger -from typst import Compiler +from typst import Compiler, TypstError from watchfiles import watch @@ -36,7 +36,13 @@ class Builder: output_path = self.public_dir / relative_path.with_suffix('.html') output_path.parent.mkdir(parents=True, exist_ok=True) - self.compiler.compile(input=path, output=output_path) + self.compiler.compile( + input=path, + output=output_path, + sys_inputs={ + 'path': str(relative_path.with_suffix('')), + }, + ) metadata = json.loads( self.compiler.query( @@ -98,7 +104,10 @@ def main() -> None: for changes in watch(site_dir): print(changes) - builder.build() + try: + builder.build() + except TypstError as e: + logger.exception(e) if __name__ == '__main__': diff --git a/site/common.typ b/site/common.typ index 5acb91a..5f41596 100644 --- a/site/common.typ +++ b/site/common.typ @@ -32,6 +32,26 @@ html.elem("img", attrs: (src: src, alt: "")) } +#let breadcrumbs() = { + let path = sys.inputs.at("path") + let parts = path.split("/") + + link(webroot)[redman.xyz] + + for (i, part) in parts.enumerate() { + let is_last = i == parts.len() - 1 + let url = parts.slice(0, i + 1).join("/") + "/index.html" + + if is_last { + " / " + part + } else { + " / " + link(webroot + url, part) + } + } +} + #let post(body, title: none, author: "Paweł Redman", date: none) = { assert(date != none, message: "missing date") @@ -74,9 +94,7 @@ }) html.header({ - html.nav[ - (nav element) // TODO when there's an index page - ] + html.nav(breadcrumbs()) }) html.main({ @@ -233,7 +233,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "jinja2", specifier = "==3.1.6" }, - { name = "loguru", specifier = ">=0.7.3" }, + { name = "loguru", specifier = "==0.7.3" }, { name = "typst", specifier = "==0.14.9" }, { name = "watchfiles", specifier = "==1.2.0" }, ] |
