Skip to content

Commit bb164d1

Browse files
committed
docs: fail the docs build when the nav references a missing page
Zensical ships a nav entry for a nonexistent page as a broken link with no diagnostic, even under --strict; MkDocs strict aborted the build. Validate the materialised nav in build_config.py so the guarantee survives the migration, and reject an empty generated API nav while at it.
1 parent 9e87ecb commit bb164d1

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

scripts/docs/build_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,40 @@
2323
ROOT = Path(__file__).parent.parent.parent
2424

2525

26+
def _missing_nav_pages(nav: list, docs_dir: Path) -> list[str]:
27+
"""Collect nav page references that don't exist under the docs dir.
28+
29+
Zensical (0.0.48) ships a nav entry for a nonexistent page as a broken
30+
link without any diagnostic, even under --strict — MkDocs aborted the
31+
build. Validating here keeps that guarantee: the concrete config never
32+
leaves this script referencing a page that isn't there.
33+
"""
34+
missing: list[str] = []
35+
for entry in nav:
36+
value = next(iter(entry.values())) if isinstance(entry, dict) else entry
37+
if isinstance(value, list):
38+
missing.extend(_missing_nav_pages(value, docs_dir))
39+
elif not (docs_dir / value).is_file():
40+
missing.append(value)
41+
return missing
42+
43+
2644
def build_config(output: Path, site_dir: str | None = None) -> None:
2745
config = yaml.safe_load((ROOT / "mkdocs.yml").read_text(encoding="utf-8"))
2846

2947
api_nav = gen_ref_pages.generate()
48+
if not api_nav:
49+
raise SystemExit("build_config: gen_ref_pages produced no API pages — did the src/ layout move?")
3050
for entry in config["nav"]:
3151
if isinstance(entry, dict) and "API Reference" in entry:
3252
entry["API Reference"] = api_nav
3353
break
3454
else:
3555
raise SystemExit("build_config: no 'API Reference' entry found in mkdocs.yml nav")
3656

57+
if missing := _missing_nav_pages(config["nav"], ROOT / "docs"):
58+
raise SystemExit(f"build_config: nav references pages that don't exist under docs/: {missing}")
59+
3760
if site_dir is not None:
3861
config["site_dir"] = site_dir
3962

0 commit comments

Comments
 (0)