""" Render every summaries/**/*.md to a sibling .html — mobile-readable (viewport meta + real font size), served alongside the .md via `tailscale serve`. Also (re)writes summaries/index.html linking every rendered page. Run after adding/editing any summary. """ import re from pathlib import Path import markdown ROOT = Path(__file__).parent / "summaries" PAGE_TEMPLATE = """ {title} {body} """ def check_svgs(md_path: Path, text: str) -> None: """O linie goală în interiorul unui face python-markdown să rupă blocul HTML în paragrafe, iar browserul aruncă restul elementelor — diagrama se randează pe jumătate, fără nicio eroare. S-a întâmplat deja de două ori; mai bine crapă aici decât să publici o diagramă stricată.""" for m in re.finditer(r"", text, re.S): if re.search(r"\n[ \t]*\n", m.group(0)): line = text[: m.start()].count("\n") + 1 raise SystemExit(f"{md_path}:{line}: linie goală în interiorul — markdown va rupe blocul") def render_file(md_path: Path) -> tuple[Path, str]: text = md_path.read_text(encoding="utf-8") check_svgs(md_path, text) body = markdown.markdown(text, extensions=["extra", "toc"]) title = text.splitlines()[0].lstrip("# ").strip() if text else md_path.stem html_path = md_path.with_suffix(".html") html_path.write_text(PAGE_TEMPLATE.format(title=title, body=body), encoding="utf-8") return html_path, title def write_index(pages: list[tuple[Path, str]]): """Grupat pe module, cu titlul H1 al fiecărei pagini — numele fișierului (o dată, un număr) nu spune nimic despre ce e înăuntru.""" sections = [] current = None for path, title in sorted(pages): if path.parent.name != current: if current is not None: sections.append("") current = path.parent.name sections.append(f"

{current.replace('_', ' ')}

") (ROOT / "index.html").write_text( PAGE_TEMPLATE.format(title="ATM — Sumarizări", body="

ATM — Sumarizări

" + "".join(sections)), encoding="utf-8", ) def main(): md_files = sorted(ROOT.glob("*/*.md")) pages = [render_file(f) for f in md_files] write_index(pages) print(f"Rendered {len(pages)} page(s) + index.html") if __name__ == "__main__": main()