Branchwell

Graphley / website / tools / build-site.py

1#!/usr/bin/env python3
2"""Render the public retirement notice and information for existing users."""
3from html import escape
4from pathlib import Path
5
6ROOT = Path(__file__).resolve().parent.parent
7NOTICE = "Graphley is no longer publicly distributed."
8NAV = '<nav aria-label="Site information"><a href="/">Status</a> <a href="/privacy/">Privacy</a> <a href="/help/">Help</a></nav>'
9
10def write(path, title, main, head="", description=NOTICE, before_footer=""):
11 title = escape(title)
12 html = f"""<!doctype html>
13<html lang="en">
14<head>
15 <meta charset="utf-8">
16 <meta name="viewport" content="width=device-width, initial-scale=1">
17 <meta name="robots" content="noindex, follow">
18 <meta name="description" content="{escape(description)}">
19 <title>{title}</title>
20 <link rel="icon" href="/favicon.png?v=mono1" type="image/png">
21 <link rel="stylesheet" href="/assets/retirement.css?v=mono1">{head}
22 <!-- no-orphans --><link rel="stylesheet" href="/no-orphans.css"><script src="/no-orphans.js" defer></script><!-- /no-orphans -->
23</head>
24<body>
25 {main}
26 {before_footer}<footer>{NAV}<p>Graphley</p></footer>
27</body>
28</html>
29"""
30 out = ROOT / path
31 out.parent.mkdir(parents=True, exist_ok=True)
32 out.write_text(html)
33
34def simple(title, message):
35 return f'<main id="main"><h1>{title}</h1><p>{message}</p></main>'
36
37VISITOR_HEAD = '\n <link rel="stylesheet" href="/assets/visitor-odometer.v1.css">\n <script defer src="/assets/visitor-odometer.v1.js"></script>'
38VISITOR_MOUNT = '<div class="visitor-welcome" data-visitor-odometer data-visitor-site="graphley"></div>'
39# Home: the open-source "make your own branch" band sits above the footer.
40BRANCH_NOTE = (ROOT / "tools/templates/branch-note.html").read_text().strip() + "\n "
41write("index.html", "Graphley", simple("Graphley", NOTICE).replace("<h1>", VISITOR_MOUNT + "<h1>", 1), VISITOR_HEAD, before_footer=BRANCH_NOTE)
42write("404.html", "Page not found · Graphley", simple("Page not found", NOTICE))
43write("download/index.html", "Graphley availability", simple("Graphley availability", NOTICE))
44write("help/index.html", "Help · Graphley", simple("Graphley help", "Graphley help is in the app."))
45write("mcp/index.html", "Local agent connections · Graphley", simple("Local agent connections", 'For the privacy implications of existing local connections, see <a href="/privacy/#mcp">Graphley privacy</a>.'))
46for page in ("privacy",):
47 write(f"{page}/index.html", f"{page.title()} · Graphley", (ROOT / "tools/templates" / f"{page}.html").read_text().strip())