#!/usr/bin/env python3 """Inject the Healthcare nav column into the pre-rendered static pages. The site is mostly static HTML under site/public/**/index.html, each carrying its own copy of the Services mega-dropdown (desktop + mobile). The Astro Base.astro layout reads src/partials/nav.html, but the static pages do NOT, so adding a sector to nav.html alone does not show up on those pages. This injects the (canonical) Healthcare block from nav.html into every static page that has the dropdown but is missing Healthcare. Idempotent. """ import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] PUBLIC = ROOT / "site" / "public" NAV = ROOT / "site" / "src" / "partials" / "nav.html" nav = NAV.read_text() m_desk = re.search( r'(.*?npi-compliance-check.*?)', nav, re.S, ) if not (m_desk and m_mob): sys.exit("Could not extract Healthcare blocks from nav.html") DESKTOP_BLOCK = m_desk.group(1) MOBILE_BLOCK = m_mob.group(1) # Desktop insertion: place the Healthcare block at the end of Column 3, right # before the "Form a Business" CTA that closes that column. DESKTOP_ANCHOR = 'Form a Business' # Mobile insertion: place Healthcare right before the mobile Corporate heading. MOBILE_ANCHOR = '

Corporate

' def inject(html: str) -> tuple[str, bool]: if "services-menu" not in html: return html, False # no dropdown on this page if "npi-compliance-check" in html: return html, False # already has Healthcare changed = False if DESKTOP_ANCHOR in html and DESKTOP_BLOCK not in html: html = html.replace(DESKTOP_ANCHOR, DESKTOP_BLOCK + " " + DESKTOP_ANCHOR, 1) changed = True if MOBILE_ANCHOR in html and MOBILE_BLOCK not in html: html = html.replace(MOBILE_ANCHOR, MOBILE_BLOCK + " " + MOBILE_ANCHOR, 1) changed = True return html, changed def main(): files = sorted(PUBLIC.rglob("index.html")) + [PUBLIC / "404.html"] touched, skipped, nodrop = 0, 0, 0 for f in files: if not f.exists(): continue html = f.read_text() new, changed = inject(html) if changed: f.write_text(new) touched += 1 elif "services-menu" not in html: nodrop += 1 else: skipped += 1 print(f"injected: {touched} already-had/partial: {skipped} no-dropdown: {nodrop}") if __name__ == "__main__": main()