Git as a CMS, syncing Markdown to PostgreSQL with a webhook

A signed GitHub webhook, a shallow fetch and one transaction. How onhlt publishes an article the moment a pull request is merged.

2 min read

Building onhlt · part 2 of 2

Cet article existe en français

Publishing on onhlt means merging a pull request. There is no admin panel and no rebuild: the site is up to date a couple of seconds after the merge.

The content repository#

Each article is a folder, with one file per language:

text
posts/2026/git-as-a-cms/
├── en.mdx
├── fr.mdx
└── cover.svg

The folder name is the translation key. It links the English and French versions, which can each have their own slug.

Verifying the webhook#

GitHub signs every delivery with HMAC SHA-256. The handler recomputes the signature over the raw body and compares it in constant time before doing anything else.

crates/onhlt-web/src/routes/internal.rsrust
fn verify(secret: &[u8], body: &[u8], header: &str) -> bool {
    let Some(hex_sig) = header.strip_prefix("sha256=") else { return false };
    let Ok(expected) = hex::decode(hex_sig) else { return false };
    let mut mac = Hmac::<Sha256>::new_from_slice(secret).expect("any key size");
    mac.update(body);
    mac.verify_slice(&expected).is_ok()
}

Fetching and replacing#

The sync job runs in the background so the webhook answers 202 Accepted immediately.

shell
git -C /var/lib/onhlt/content fetch --depth 1 origin main
git -C /var/lib/onhlt/content reset --hard FETCH_HEAD

Replacing everything sounds wasteful, but a blog has hundreds of documents, not millions. The transaction takes milliseconds and readers never see a half-synced site, thanks to MVCC.

Drafts and previews#

A post with draft: true is indexed but not listed. It gets a preview URL derived from an HMAC of its key, so it can be shared for review without being guessable.

That is the whole CMS: Git for writing and review, Rust for validation, PostgreSQL for queries.

Written by

Software, backend and DevOps engineer. I write Rust, run Kubernetes and measure everything with OpenTelemetry.

↑↓ navigate ↵ open Esc close