Make catalog PDF links host-relative and add a hostname rewrite script.
Some checks are pending
offline / test (push) Waiting to run

New builds write path-relative PDF annotations so the tree can be served
from docs.verae-time.net (or any host at the site root) without a rebuild.
scripts/rewrite-docs-host.py retargets an already-built site when absolute
URLs are preferred. Live service doors stay on their own hostnames.
This commit is contained in:
George Lambert 2026-09-11 23:00:12 -04:00
parent 85b5b53ea9
commit 20155de96b
4 changed files with 246 additions and 40 deletions

View file

@ -5,7 +5,6 @@ from __future__ import annotations
import sys
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import unquote, urljoin, urlparse
ROOT = Path(__file__).resolve().parents[1]
SITE = ROOT / "site"
@ -24,23 +23,46 @@ class Anchors(HTMLParser):
self.hrefs.append(d["href"] or "")
def _exists(dest: Path) -> bool:
if dest.is_file():
return True
if dest.is_dir() and any(
(dest / n).exists() for n in ("index.html", "index.pdf", "README.html", "README.pdf")
):
return True
return False
def local_ok(url: str) -> bool:
if url.startswith(WEB):
rel = url[len(WEB) :].split("#", 1)[0]
dest = SITE / rel
if dest.is_file():
return True
if dest.is_dir() and any(
(dest / n).exists() for n in ("index.html", "index.pdf", "README.html", "README.pdf")
):
return True
# yaml/svg/png on homepage
return False
if url.startswith(WEB) or url.startswith("http://zapier.georgelambert.org/"):
rel = url.split("://", 1)[-1].split("/", 1)[-1].split("#", 1)[0]
return _exists(SITE / rel)
if url.startswith("file:"):
return False
return True # http(s) off-site; homepage checker uses GET separately
def pdf_dest_ok(pdf: Path, raw: str) -> bool:
raw = raw.split("#", 1)[0]
if raw.startswith("file:"):
return False
if raw.startswith("mailto:") or raw.startswith("data:"):
return True
if raw.startswith("http://") or raw.startswith("https://"):
if raw.startswith(WEB) or raw.startswith("http://zapier.georgelambert.org/"):
return local_ok(raw)
return True
if raw.startswith("/"):
dest = SITE / raw.lstrip("/")
else:
dest = (pdf.parent / raw).resolve()
try:
dest.relative_to(SITE.resolve())
except ValueError:
return False
return _exists(dest)
def main() -> int:
idx = SITE / "index.html"
if not idx.exists():
@ -91,12 +113,10 @@ def main() -> int:
n_file += 1
broken.append(f"file URI {pdf.relative_to(SITE)} -> {raw[:120]}")
continue
if raw.startswith(WEB):
path = raw.split("#", 1)[0]
if "/research/" in path:
continue
if not local_ok(path):
broken.append(f"pdf missing {pdf.relative_to(SITE)} -> {raw}")
if "/research/" in raw:
continue
if not pdf_dest_ok(pdf, raw):
broken.append(f"pdf missing {pdf.relative_to(SITE)} -> {raw}")
print(f"file:// leftover {n_file}")
print(f"broken {len(broken)}")