From e98fac942f149b9870790c112e082733b40535a9 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 14 Jun 2026 20:40:20 +0200 Subject: just + linters --- build.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'build.py') diff --git a/build.py b/build.py index 3838d57..24e8fac 100644 --- a/build.py +++ b/build.py @@ -2,7 +2,6 @@ import json import os -import re import shutil from dataclasses import dataclass from datetime import datetime @@ -19,8 +18,6 @@ class CompiledPage: date: datetime - - class Builder: def __init__(self, site_dir: Path, static_dir: Path, public_dir: Path) -> None: self.site_dir = site_dir @@ -31,18 +28,20 @@ class Builder: def _compile_typst_page(self, path: Path) -> CompiledPage: relative_path = path.relative_to(self.content_dir) - print(relative_path) + print(f'Typst: {relative_path}') 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) - metadata = json.loads(self.compiler.query( - selector='', - field='value', - one=True, - )) + metadata = json.loads( + self.compiler.query( + selector='', + field='value', + one=True, + ) + ) return CompiledPage( url=str(relative_path.with_suffix('.html')), @@ -55,32 +54,33 @@ class Builder: ) def _compile_typst_pages(self) -> list[CompiledPage]: - return [ - self._compile_typst_page(path) - for path in self.content_dir.rglob('*.typ') - ] + return [self._compile_typst_page(path) for path in self.content_dir.rglob('*.typ')] def _compile_index_page(self, pages: list[CompiledPage]) -> None: pages.sort(key=lambda page: page.date) template = jinja2.Template((self.site_dir / 'index.html').read_text()) (self.public_dir / 'index.html').write_text(template.render(pages=pages)) - def build(self) -> None: + print(f'Removing {str(self.public_dir)!r}...') + shutil.rmtree(self.public_dir, ignore_errors=True) + self.public_dir.mkdir(parents=True, exist_ok=True) + + print('Linking static directory...') + (self.public_dir / 'static').symlink_to(self.static_dir) + pages = self._compile_typst_pages() + + print('Building index page...') self._compile_index_page(pages) def main() -> None: repo_dir = Path(__file__).parent site_dir = repo_dir / 'site' - content_dir = site_dir / 'content' public_dir = repo_dir / 'public' static_dir = repo_dir / 'static' - shutil.rmtree(public_dir, ignore_errors=True) - shutil.copytree(repo_dir / 'static', public_dir / 'static') - os.environ['TYPST_FEATURES'] = 'html' builder = Builder(site_dir=site_dir, static_dir=static_dir, public_dir=public_dir) -- cgit