"""Builds the self-contained HTML page from the sessions. The result needs neither network nor server: the data and the transcripts are embedded inside and it opens with a double click. """ import json from importlib import resources MARKER = "__DATA__" TEMPLATE_NAME = "template.html" class TemplateError(Exception): """The template does not have the shape the generator expects.""" def template_text(path=None): if path: with open(path, encoding="utf-8") as f: return f.read() return (resources.files(__package__) / TEMPLATE_NAME).read_text(encoding="utf-8") def build_payload(sessions, memories=None): """Structure that travels embedded in the page. An object rather than a list because the page shows two different things: sessions and project memories. """ return {"s": list(sessions), "m": list(memories or ())} def encode_payload(payload): """Serializes the payload to put it inside a