1- """Produce the concrete Zensical build config from `` mkdocs.yml` `.
1+ """Produce the concrete Zensical build config from `mkdocs.yml`.
22
3- Zensical builds from `` mkdocs.yml` ` directly, but it has no equivalent of
4- `` mkdocs-literate-nav`` : the `` API Reference`` navigation has to be materialised
5- as explicit entries. This script regenerates the `` docs/api/` ` tree (via
6- :mod:` gen_ref_pages` ) and writes `` mkdocs.gen.yml`` with the real API nav
7- spliced in — that generated file is what `` zensical build``/`` serve` ` consumes.
3+ Zensical builds from `mkdocs.yml` directly, but it has no equivalent of
4+ mkdocs-literate-nav: the " API Reference" navigation has to be materialised
5+ as explicit entries. This script regenerates the `docs/api/` tree (via
6+ gen_ref_pages) and writes `mkdocs.gen.yml` with the real API nav spliced
7+ in — that generated file is what `zensical build`/` serve` consumes.
88
99Usage:
10- python scripts/docs/build_config.py [--site-dir DIR] [--output FILE]
10+ python scripts/docs/build_config.py
1111"""
1212
1313from __future__ import annotations
1414
15- import argparse
1615from pathlib import Path
1716
1817# Both scripts live in this directory, which Python puts on sys.path[0] when
@@ -36,12 +35,12 @@ def _missing_nav_pages(nav: list, docs_dir: Path) -> list[str]:
3635 value = next (iter (entry .values ())) if isinstance (entry , dict ) else entry
3736 if isinstance (value , list ):
3837 missing .extend (_missing_nav_pages (value , docs_dir ))
39- elif not (docs_dir / value ).is_file ():
38+ elif "://" not in value and not (docs_dir / value ).is_file ():
4039 missing .append (value )
4140 return missing
4241
4342
44- def build_config (output : Path , site_dir : str | None = None ) -> None :
43+ def build_config () -> None :
4544 config = yaml .safe_load ((ROOT / "mkdocs.yml" ).read_text (encoding = "utf-8" ))
4645
4746 api_nav = gen_ref_pages .generate ()
@@ -57,19 +56,9 @@ def build_config(output: Path, site_dir: str | None = None) -> None:
5756 if missing := _missing_nav_pages (config ["nav" ], ROOT / "docs" ):
5857 raise SystemExit (f"build_config: nav references pages that don't exist under docs/: { missing } " )
5958
60- if site_dir is not None :
61- config ["site_dir" ] = site_dir
62-
59+ output = ROOT / "mkdocs.gen.yml"
6360 output .write_text (yaml .safe_dump (config , sort_keys = False , allow_unicode = True ), encoding = "utf-8" )
6461
6562
66- def main () -> None :
67- parser = argparse .ArgumentParser (description = __doc__ )
68- parser .add_argument ("--site-dir" , default = None , help = "Override the build output directory." )
69- parser .add_argument ("--output" , default = str (ROOT / "mkdocs.gen.yml" ), help = "Where to write the generated config." )
70- args = parser .parse_args ()
71- build_config (Path (args .output ), args .site_dir )
72-
73-
7463if __name__ == "__main__" :
75- main ()
64+ build_config ()
0 commit comments