precommit.sh 721 Bytes
#!/bin/bash
# Pre-commit hook: rebuild the static site so committed HTML stays in sync with markdown.
# Install: ln -s ../../scripts/precommit.sh .git/hooks/pre-commit && chmod +x scripts/precommit.sh
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"

# Only run if any markdown or mkdocs config changed
if git diff --cached --name-only | grep -qE '\.(md|yml)$|mkdocs\.yml'; then
  if [ ! -d .venv ]; then
    echo "pre-commit: .venv missing; run 'python3 -m venv .venv && pip install -r requirements.txt'" >&2
    exit 1
  fi
  source .venv/bin/activate
  mkdocs build --strict
  # Stage the regenerated site/ if it's tracked
  if git ls-files --error-unmatch site/ >/dev/null 2>&1; then
    git add site/
  fi
fi