"""Wrap every fragment in src/ with the panel shell and write it next to this file. The mockups are static HTML, but thirty pages share one navbar; keeping that navbar in one place is the only reason this script exists. Run it from anywhere: python docs/assets/panel-redesign/panel/build.py A fragment starts with one meta comment: section/page pick the highlighted entries; "shell: bare" skips the navbar (sign-in, setup). """ import pathlib import re HERE = pathlib.Path(__file__).parent NAV = [ ("overview", "Overview", "overview.html", "ti-activity-heartbeat", []), ("outbound", "Outbound", "out-domains.html", "ti-send", [ ("domains", "Domains", "out-domains.html", "ti-world-upload"), ("log", "Log", "out-log.html", "ti-list-details"), ("queue", "Queue", "out-queue.html", "ti-stack-2"), ("dmarc", "DMARC reports", "dmarc.html", "ti-report-analytics"), ]), ("inbound", "Inbound", "in-domains.html", "ti-inbox", [ ("domains", "Domains", "in-domains.html", "ti-world-download"), ("log", "Log", "in-log.html", "ti-list-details"), ("queue", "Queue", "in-queue.html", "ti-stack-2"), ("quarantine", "Quarantine", "in-quarantine.html", "ti-mail-pause"), ("filter-lists", "Filter lists", "in-filter-lists.html", "ti-filter"), ]), ("server", "Server", "health.html", "ti-server-2", [ ("health", "Health", "health.html", "ti-heartbeat"), ("preflight", "Preflight", "preflight.html", "ti-checklist"), ("system-log", "System log", "system-log.html", "ti-file-text"), ("backup", "Backup", "backup.html", "ti-archive"), ("users", "Users", "users.html", "ti-users"), ("settings", "Settings", "settings.html", "ti-settings"), ]), ] HEAD = """ {title} · SelfPost """ FOOT = ('') def navbar(section, page): out = ['', ''] return "\n".join(out) def subnav(section, page): for key, _label, _href, _icon, pages in NAV: if key == section and pages: cur = ' aria-current="page"' links = "".join( f'{plabel}' for pkey, plabel, phref, picon in pages) return f'
{links}
' return "" def build(path): text = path.read_text(encoding="utf-8") m = re.match(r"\s*\s*", text, re.S) meta = dict(part.split(":", 1) for part in m.group(1).split("|")) meta = {k.strip(): v.strip() for k, v in meta.items()} body = text[m.end():] html = HEAD.format(title=meta["title"]) if meta.get("shell") == "bare": html += f"\n{body}\n\n\n" else: section, page = meta.get("section", ""), meta.get("page", "") html += (f"\n{navbar(section, page)}\n{subnav(section, page)}\n
\n" f'
\n{body}\n {FOOT}\n
\n
\n\n\n') (HERE / path.name).write_text(html, encoding="utf-8", newline="\n") if __name__ == "__main__": pages = sorted((HERE / "src").glob("*.html")) for p in pages: build(p) print(f"built {len(pages)} pages")