#!/usr/bin/env python3 """Build a static, fully browsable HTML edition of the Geometry textbook. Sources stay untouched. Everything is written to ./site/ : site/index.html portal: chapters, PDFs, guides, teacher material site/Markdown/*.html the book (converted from Markdown/) site/Study_Guides/*.html study guides and lesson one-pagers site/Other/lessonplans_md/ teacher's lesson plans and chapter notes site/Exams/ exam paper + answer key site/assets/ stylesheet, scripts, search index site/*.pdf hard links to the PDFs in the project root Images are hard linked, so the site costs almost no extra disk space. Usage: python3 site_builder/build.py # rebuild everything The result is ./site/index.html — open it in any browser, or serve the whole folder with `python3 -m http.server -d site`. """ from __future__ import annotations import html import hashlib import json import os import re import shutil import subprocess import sys from collections import defaultdict from concurrent.futures import ThreadPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parent.parent BUILDER = Path(__file__).resolve().parent SITE = ROOT / "site" PANDOC = shutil.which("pandoc") def _asset_version() -> str: digest = hashlib.md5() for name in ("style.css", "print.css", "app.js"): path = BUILDER / name if path.exists(): digest.update(path.read_bytes()) return digest.hexdigest()[:10] ASSET_VER = _asset_version() PAGE_RE = re.compile(r"^[ \t]*[ \t]*$", re.M) TITLE_RE = re.compile(r"
{esc(display)}
\n\n' def md_to_text(text: str) -> str: text = PAGE_RE.sub(" ", text) text = re.sub(r"```.*?```", " ", text, flags=re.S) text = re.sub(r"!\[([^\]]*)\]\([^)]*\)", r"\1", text) text = re.sub(r"\[([^\]]*)\]\([^)]*\)", r"\1", text) text = re.sub(r"<[^>]+>", " ", text) text = text.replace("$", " ") text = re.sub(r"^\s*\|?[\s:|-]{3,}\|?\s*$", " ", text, flags=re.M) text = re.sub(r"[#>*_`|~]+", " ", text) text = re.sub(r"[ \t]+", " ", text) text = re.sub(r"\s*\n\s*", "\n", text) return text.strip() def extract_title(body: str) -> str | None: m = TITLE_RE.search(body) if not m: return None title = strip_tags(m.group(1)) return re.sub(r"\s+", " ", title).strip() or None def build_toc(body: str) -> str: items = [] for m in HEAD_RE.finditer(body): level = int(m.group(1)) ident = m.group(2) label = re.sub(r"\s+", " ", strip_tags(m.group(3))) if label: items.append((level, ident, label)) if len(items) < 2: return "" out = ['{esc(lede)}
' f'Harold R. Jacobs · Third edition
The complete textbook, every chapter as HTML and PDF, plus the study guides, lesson one-pagers, the answers, teacher’s lesson plans, and exams — all in one browsable place.
{stats}
Open a chapter to see its lessons. Every section is readable online; the PDF button opens the original.
Selected answers for every chapter, one page per chapter, plus the complete key.
Vocabulary, rules, worked examples, and homework helpers for every lesson.
From A Teacher’s Guide to Geometry — lesson plans and chapter notes.
The chapter 1–2 test and its answer key.
Search
Search the full text of the textbook, the study guides and one-pagers, the teacher’s lesson plans, and the exam answer key.
Type at least two characters.