fix: record list parts by their front matter

This commit is contained in:
Abdessamad Derraz committed 2026-11-05 12:24:18 +01:00
1 parent 3a36350f5c
commit 1e96968744
4 files changed
+272 -8

No files matched your search

+5 -5
View File
@@ -3357,6 +3357,8 @@ def _published_parts() -> dict[str, str]:
def _parent_page(link: str) -> str:
"""The page a `parent:` link names (/platforms/batocera/), under docs/."""
path, _, fragment = link.partition("#")
# Written with the site's base (/retrobios/emulators/x/) or without it.
path = path.removeprefix(sitestarlight.BASE.rstrip("/"))
stem = path.strip("/") or "index"
return f"{stem}.md" + (f"#{fragment}" if fragment else "")
@@ -3374,13 +3376,11 @@ def record_parts(docs: Path, present: set[str], published: dict[str, str]) -> di
if not page.is_file():
page = page.with_suffix(".mdx")
try:
with page.open(encoding="utf-8") as handle:
head = handle.read(2048)
parent = _front_matter(page.read_text(encoding="utf-8")).get("parent")
except OSError:
continue
link = re.search(r"^parent:\n(?: .*\n)*? link: (\"[^\"\n]*\")", head, re.M)
if link and rel not in found:
found[rel] = _parent_page(json.loads(link[1]))
if isinstance(parent, dict) and parent.get("link") and rel not in found:
found[rel] = _parent_page(str(parent["link"]))
return dict(sorted(found.items()))
+3 -2
View File
@@ -819,12 +819,13 @@ def redirects(profiles: dict, present: set[str],
that is already a page's address, is left out. Addresses are written
under the site root, without its base. ``moved`` adds pages that moved
by generation, old page to new page, the new one with an optional
#fragment."""
#fragment. A page MOVED_PAGES names keeps that target over the part
record: cross-reference-minui is answered on MinUI's own page."""
def address(rel: str) -> str:
page, _, fragment = rel.partition("#")
return "/" + page_url(page)[len(BASE):] + (f"#{fragment}" if fragment else "")
out = {address(old): address(new) for old, new in {**MOVED_PAGES, **(moved or {})}.items()
out = {address(old): address(new) for old, new in {**(moved or {}), **MOVED_PAGES}.items()
if old not in present and new.partition("#")[0] in present}
pages = {rel.casefold() for rel in present}
claims: dict[str, set[str]] = {}