← Knowledge Base
PythonFrom my setup3 min read · updated 2026-11-27

How this website is built: a static-site generator in Python

A tour of the setup behind this site: Python scripts that turn JSON, Markdown and cached GitHub data into static HTML, one hashed stylesheet, client-side search, tests, and a deployment script with a backup and rollback.

pythonstatic-sitegithub-apideploymenttesting

This site has no application server and no database. A set of small Python scripts reads content files and writes plain HTML, and nginx serves the result. On a small 1 GB VM that is the cheapest, fastest and safest design I could find.

The idea

content/ (JSON, Markdown, text) + cached GitHub data
        └─> scripts/build_*.py ─> stack/site/ (HTML, CSS, JS, JSON) ─> deploy ─> Caddy ─> nginx

build_all.py runs one builder per area: the home page, the project portfolio and one page for every project, the knowledge base, the infrastructure page, the poetry archive, the links page, the cheat sheets and the search index. Each builder is a plain script that can also be run alone.

Content is just files

  • Projects come from the public GitHub API, plus a config.json (categories, display names, featured list) and optional per-project overrides.
  • Knowledge-base articles are Markdown files with a small front-matter block; the builder renders them, adds a table of contents, reading time and syntax highlighting, and sanitises the HTML so an article cannot inject scripts.
  • Poems are a JSON list. A test stores a SHA-256 of every poem and fails if the generator ever changes a character.

GitHub data without surprises

The repository list, releases and READMEs are cached on disk. The builder tracks GitHub's rate-limit header, stops asking when it runs low, and falls back to the cache on any error. Visitors never contact GitHub: everything is baked into the pages, and no token appears in the frontend.

One stylesheet, one script

All styling is one CSS file built on custom properties (colour, spacing, radius, type scale), with a dark and a light theme and prefers-reduced-motion support. The CSS and JS are written as site.<hash>.css|js so the web server can cache them for a year; the name changes whenever the content does.

Search without a backend

At build time the generator writes one search-index.json with the projects, articles, poems, experience and pages. The browser downloads it only when search is opened (Ctrl+K or /), then matches words with accents ignored, so "greseala" finds "greșeala".

Tests

The tests run against the generated site. They check that the original content is preserved (project count and categories, every poem's hash, links, commands, CV entries), that every internal link and asset resolves, that titles and canonical URLs are unique, that structured data parses, that nothing that looks like a private address or key is in the public files, and that the sanitiser, the infrastructure leak guard and the GitHub rate-limit fallback behave.

python -P scripts/build_all.py
python -P -m unittest discover -s tests

Deployment with a safety net

The deploy script builds, runs the tests, validates the new Caddy configuration on the server before it replaces the live one, backs up the current production site, uploads, reloads Caddy gracefully and then checks a list of live URLs. If a check fails it prints the exact command to roll back, or rolls back by itself when asked to.

What I would change

The Content-Security-Policy still has to allow inline scripts and styles, because pages carry small inline snippets; moving them into the shared script and using hashes or nonces would tighten it. A second small VM would also let monitoring run away from the site it watches.