pre-commit
tools/git-hooks/pre-commit
#!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
# Regenerate menu + search index when a page is staged. Page content feeds the
# index, so html/md/txt (and extensionless pages) count, not only .html.
# The two generated files themselves do not trigger it; regeneration is
# idempotent, so it also overwrites a stale hand-staged copy.
staged=$(git diff --cached --name-only --diff-filter=ACMRD)
if echo "$staged" | grep -vE '^includes/(something-in-the-body\.html|search-index\.json)$' \
| grep -qE '(\.(html|md|txt)$|(^|/)[^./]+$)'; then
python3 tools/generate-menu.py
git add includes/something-in-the-body.html includes/search-index.json
fi