import os
import nbformat
def fix_notebook(src: str, dst: str) -> None:
"""Copy one notebook, filling in blank kernel/language metadata Quarto needs.
Nothing in the notebook is executed: it is only read and re-written.
"""
nb = nbformat.read(src, as_version=4)
md = nb.metadata
kernelspec = md.get("kernelspec") or {}
language_info = md.get("language_info") or {}
language = kernelspec.get("language") or language_info.get("name") or "python"
if not kernelspec.get("name"):
kernelspec.update(name="python3", display_name="Python 3")
kernelspec["language"] = kernelspec.get("language") or language
language_info["name"] = language_info.get("name") or language
md["kernelspec"], md["language_info"] = kernelspec, language_info
nbformat.write(nb, dst)
# keep the original timestamp so the page's "Last updated" is accurate
st = os.stat(src)
os.utime(dst, (st.st_atime, st.st_mtime))How this site works
This site is built automatically from Jupyter notebooks. Notebooks are written and edited on a private Jupyter server. Anything placed in one folder there is published here, usually within a minute or two. Nothing else on that server is exposed.
This page explains how the pipeline works: how notebooks get from the editor to this page, how rebuilds happen without downtime, and how the setup is locked down.
The short version
Private Jupyter server Isolated web container Internet
────────────────────── ────────────────────── ────────
public/
├─ About/ ── one-way ──► incoming/ ──► Quarto build ──► live site ──► reverse proxy (HTTPS) ──► you
└─ <other folders>/ push (SSH) (no code run) (atomic swap)
- Write: notebooks are edited on a private Jupyter server. Only the
public/folder is ever copied anywhere. - Push: once a minute the Jupyter server pushes changed files from
public/to a separate, isolated web container. - Build: the web container checks every minute for changes and, if there are any, turns the notebooks into this website with Quarto.
- Swap: the new version is switched in instantly; the old one stays live until then.
- Serve: a web server in the container serves the files, behind a reverse proxy that provides HTTPS.
The pieces
| Piece | Job |
|---|---|
| Jupyter server (private) | Where notebooks are written. Requires a login and is never exposed by this site. |
public/ folder |
The only thing that gets published. Each top-level folder becomes a section in the sidebar. |
| Sync job | Runs every minute on the Jupyter server. Pushes public/ with rsync over SSH, copying only files whose contents changed and removing anything deleted. |
| Web container | A small, separate Linux container that exists only to build and serve this site. |
| Quarto | Turns notebooks into web pages: sidebar, search, light/dark mode, code highlighting. |
| nginx | Serves the finished static files. |
| Reverse proxy | Terminates HTTPS (Let’s Encrypt certificate) and forwards requests to the web container. |
| Monitor | A separate job that checks the site from outside and sends a phone alert if it goes down or a build fails. |
How long changes take
| Step | How often | Typical time |
|---|---|---|
| Push from Jupyter | every minute, on the minute | about 1 s |
| Check for changes | every minute, 30 s after the push | instant if nothing changed |
| Build | only when something changed | about 30-40 s |
So a saved change is usually live in 1-2 minutes. Adding, editing, renaming or deleting a notebook or folder all count as changes.
Rebuilds without downtime
Quarto clears its output folder at the start of every build, so building straight into the folder the web server reads would leave the site broken for half a minute each time. Instead:
- Quarto builds into a separate staging folder.
- The result is copied into whichever of two release folders (
aorb) is not live. - A symlink,
current, is switched to point at the new folder. A rename is atomic, so visitors get either the old site or the new one, never a half-built one. - If the build fails, the swap never happens and the previous version simply stays live.
cur=$(readlink /srv/www/current) # a or b
next=a; [ "$cur" = a ] && next=b
rsync -a --delete _build/ "/srv/www/$next/"
ln -sfn "$next" /srv/www/current.tmp
mv -T /srv/www/current.tmp /srv/www/current # atomic switchNot in search engines
This site is meant to be shared by link, not found by search:
- Every response carries an
X-Robots-Tag: noindex, nofollow, noarchiveheader, and every page has the matching<meta name="robots">tag. robots.txtdeliberately allows crawling. If crawlers were blocked they could never see thenoindexinstruction, and a page linked from elsewhere could still show up in results without a description.
Link previews in messaging apps still work: each page has Open Graph tags (title, description, preview image).
Security and privacy design
The aim is that the public site can’t be used to reach anything private, even if the web container were compromised.
- Only one folder is published. Everything outside
public/stays on the private server. Hidden files and Jupyter checkpoint folders are excluded even inside it. - Code is shown, never run. Notebook execution is switched off in the build (
execute: enabled: false), so code appears with whatever output was saved, but nothing in a notebook runs on the public side. - One-way push. The Jupyter server pushes to the web container, never the other way round, so the web container holds no credentials for the private server.
- The push key can do one thing. The SSH key that the Jupyter server uses can only write files into the web container’s incoming folder (
rrsync, with all other SSH features disabled). It can’t open a shell. - Separate users. One account receives files, another builds the site, and nginx only reads the finished output.
- Locked-down network. The web container’s firewall accepts web traffic only from the reverse proxy, and SSH only from the Jupyter server. Outbound, it can reach the internet (for updates) but cannot open connections to anything on the local network.
- Unprivileged container. It runs as an unprivileged Linux container with security updates applied automatically.
- Static output only. What visitors get is plain HTML, CSS and JavaScript. There is no database, no login and no server-side code to attack.
- Sensible headers.
X-Content-Type-Options,Referrer-PolicyandX-Frame-Optionsare set on every response. Pages always revalidate, so a deleted page disappears straight away rather than lingering in browser caches.
Monitoring
A small script runs every 5 minutes outside the web container:
- It loads the home page over HTTPS, the same way a visitor would. If that fails twice in a row, a phone notification is sent, and another when it recovers.
- It reads the build status. If the last build failed, it sends an alert (the old version stays live, so nothing breaks for visitors), and another once a build succeeds again.
Running the check elsewhere means the web container never needs access to the local network.
Other details
- “Last updated” under each page title is the time that notebook last changed. It comes from the file’s timestamp, which the sync sets when a changed file arrives.
- 404 page. Missing pages get a proper “Page not found” page with a button back to the home page.
- Logs are rotated weekly so they can’t grow without limit.
Fixing notebook metadata before the build
Quarto needs every notebook to declare its language. Notebooks created through the Jupyter API sometimes have that metadata blank, so before each build a small Python script copies the incoming notebooks into the build folder and fills in anything missing. It keeps each file’s timestamp so “Last updated” stays accurate. The core of it is below. This cell isn’t run when the site is built, which also shows what code looks like on the site.
Site configuration
The main Quarto settings (_quarto.yml), lightly trimmed:
project:
type: website
output-dir: _build # staging folder, swapped in when complete
render:
- index.qmd
- 404.qmd
- "notebooks/**/*.ipynb"
website:
title: "Callum's Notebooks"
site-url: https://notebooks.callumgriffin.com
search: true
sidebar:
style: docked # sections generated from the folders in public/
date: last-modified # shown as "Last updated"
execute:
enabled: false # show code, never run it
format:
html:
theme:
light: cosmo
dark: darkly
toc: true
code-copy: true
code-tools: true
include-after-body: _rebuild-banner.htmlAdding something to the site
- Create or move a notebook into
public/on the Jupyter server. Use a sub-folder to get a new sidebar section (folderMy-Topicbecomes My Topic). - Start notebook file names with a number (
00-,01-, …) to control their order. - Give each notebook a
# Titleas its first heading. That becomes the page title. - Save. The page appears within a couple of minutes, with the blue banner showing while it builds.
To take something down, delete it or move it out of public/. It disappears on the next build.