#!/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"", re.S) def canonical_nav() -> str: """Extract the canonical block from the partial.""" partial = NAV_PARTIAL.read_text() m = NAV_RE.search(partial) if not m: sys.exit(f"ERROR: no block found in {NAV_PARTIAL}") if "services-menu" not in m.group(0): sys.exit(f"ERROR: canonical nav in {NAV_PARTIAL} is missing the Services dropdown") return m.group(0) def static_pages() -> list[Path]: files = sorted(PUBLIC.rglob("index.html")) fof = PUBLIC / "404.html" if fof.exists(): files.append(fof) return files def sync(check_only: bool) -> int: canon = canonical_nav() pages = static_pages() out_of_sync: list[Path] = [] changed = 0 skipped_no_nav = 0 for f in pages: html = f.read_text() if "services-menu" not in html: skipped_no_nav += 1 continue m = NAV_RE.search(html) if not m: # has services-menu text but no