#!/usr/bin/env python3
"""Single source of truth for the site header / Services mega-dropdown.
Background
----------
The marketing site is served from two rendering systems that historically each
carried their OWN copy of the header markup, which is why the Services dropdown
drifted out of sync (dev.performancewest.net vs the order pages vs everything
else):
1. Astro pages (site/src/pages/**/*.astro) -> layouts/Base.astro reads
src/partials/nav.html and injects it.
2. Pre-rendered static pages (site/public/**/index.html, 404.html) each
embedded a hard-coded block.
This script makes ``site/src/partials/nav.html`` the ONE canonical source and
rewrites the block of every static page to match it byte-for-byte.
It is idempotent and safe to run on every build/deploy.
Canonical block
---------------
``nav.html`` is a single line that begins with the document
tag and the
"" comment, followed by exactly one ```` block.
The portion is what gets synced into the static pages (their own
attributes are preserved).
Usage
-----
python3 scripts/sync_nav.py # rewrite static pages from nav.html
python3 scripts/sync_nav.py --check # exit 1 if any page is out of sync
Run with --check in CI / pre-commit to guarantee the header never drifts again.
"""
from __future__ import annotations
import argparse
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
PUBLIC = ROOT / "site" / "public"
NAV_PARTIAL = ROOT / "site" / "src" / "partials" / "nav.html"
NAV_RE = re.compile(r"