Dump all JSONHTL notes from a remote server endpoint to static HTML files.
Inputs:
• base_url (str) — HTTP endpoint returning dict[str, JSONHTL document]
• outdir (Path or str) — output directory
Behaviour:
• Fetch all notes via fetch_all_notes_from_server(base_url)
• Validate note keys and document structure
• Render each document to HTML using render_document
• Write each file using write_html
• Fail fast on any malformed key or document
from pathlib import Path
def process_server_notes(base_url, outdir):
if not isinstance(base_url, str) or not base_url.strip():
raise ValueError("base_url must be a non-empty string")
notes = fetch_all_notes_from_server(base_url)
if not isinstance(notes, dict):
raise TypeError("Server response must be a dict mapping keys to documents")
outdir = Path(outdir)
outdir.mkdir(parents=True, exist_ok=True)
for key, doc in notes.items():
if not isinstance(key, str) or not key.strip():
raise ValueError(f"Invalid note key: {key!r}")
if key.startswith('/'):
raise ValueError(f"Note key must not start with '/': {key}")
if not isinstance(doc, dict):
raise TypeError(f"Document for key {key!r} is not a dict")
if 'title' not in doc or 'content' not in doc:
raise ValueError(f"Document for key {key!r} missing required fields")
html_text = render_document(doc)
write_html(outdir, key, html_text)