"""Patch all built HTML files so the sidebar title link goes to /Threadwell/.
The `
` link is generated by the
`@quartz-community/page-title` plugin from a relative href that breaks
when the URL bar lacks a trailing slash. We rewrite the href to the
absolute site base path so it never lands on the bare domain.
Idempotent. Safe to re-run.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
SCRIPT = Path(__file__).resolve()
VAULT = SCRIPT.parents[2]
# Detect base path from the publish overlay if present, else default to /Threadwell/
overlay = VAULT / "publish" / "quartz.config.yaml"
site_base = "/Threadwell/"
if overlay.is_file():
for line in overlay.read_text(encoding="utf-8").splitlines():
if line.startswith("baseUrl:"):
host = line.split(":", 1)[1].strip()
if "/" in host:
site_base = "/" + host.split("/", 1)[1].rstrip("/") + "/"
else:
site_base = "/"
break
PUBLIC = VAULT / "site" / "public"
PATTERN = re.compile(
r'(