Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,8 @@ renders no post under `mkdocs-static-i18n` and warns on its archive pages.
arrow, east within the site and north-east off it, and a teal wash on hover.
- Link to the TileOPs repo rather than duplicating it. A page authored here that
mirrors upstream content will drift.
- `hooks.py` appends a content hash to each local `extra_css` URL, so a changed
stylesheet reaches readers whose browser cached the old one. Do not add a
`?v=` by hand.
- Gitignored: `site/`, `__pycache__/`, `.cache/`, `TileOPs/`, and
`docs/benchmarks/` except `index.md`.
20 changes: 19 additions & 1 deletion hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
marks those lists for extra.css, which draws each item as a card.
* A page merged into another leaves its old URL behind; `on_post_build` writes
a redirect there, so published links keep working.
* The stylesheet's URL carries a hash of its content, set in `on_config`, so a
browser holding an older copy fetches the new one as soon as it changes.
"""
from __future__ import annotations

import hashlib
import os
import re

Expand Down Expand Up @@ -81,8 +84,23 @@ def on_page_markdown(markdown, page, config, files):
]


def _bust_css_cache(config):
"""Append `?v=<content hash>` to each local stylesheet in `extra_css`."""
out = []
for entry in config["extra_css"]:
path = os.path.join(config["docs_dir"], str(entry))
if "?" in str(entry) or not os.path.isfile(path):
out.append(entry)
continue
with open(path, "rb") as f:
digest = hashlib.sha256(f.read()).hexdigest()[:10]
out.append(f"{entry}?v={digest}")
config["extra_css"] = out


def on_config(config):
"""Expand the Benchmarks nav entry to the generated pages."""
"""Version the stylesheet URL; expand the Benchmarks nav entry."""
_bust_css_cache(config)
bench_dir = os.path.join(config["docs_dir"], "benchmarks")
if not os.path.isdir(bench_dir):
return config
Expand Down
Loading