bānhūs

“bone house”

a pico-SSG for bone heads like me

import jinja2, shutil
from pathlib import Path

env = jinja2.Environment(loader=jinja2.FileSystemLoader("src"))

for dir in Path("src").iterdir():
    if dir.name[0] == "_":
        continue
    for file in dir.iterdir():
        if file.name[0] == "_":
            continue
        dest = Path("dist", dir.name, file.name)
        if file.suffix == ".html":
            html = env.get_template(f"{dir.name}/{file.name}").render()
            dest.write_text(html)
        else:
            shutil.copy2(file, dest)

code snippet is for illustrative purposes only. view the full source at /banhus.py

about

Any Jinja template at a path under src/ is rendered to the same path in dist/. Ordinary files (images, CSS, etc.) are copied into the dist/ directory unchanged.

Any file or directory beginning with _ is input-only. Files such as _this.html and _this/file.html can be included or extended, but are not written to dist/.

try it out

Download /banhus.py, create Jinja templates in a src/ directory and then build the site with python3 banhus.py. To spin up a local server that refreshes as you edit your site, run python3 banhus.py dev.

config.py

Write your own (optional) config.py file to provide global state for your templates to access. By default, templates will have access to a pages state object, containing metadata of all pages in the site.

markdown

Markdown is rendered to HTML using the nearest _md.html Jinja template.

the name

bānhūs is an Old English kenning: “bone-house,” meaning the body.