gen_pages.py (1275B)
1 """ 2 Auto-discover markdown files from the repo and expose them as virtual MkDocs pages. 3 4 README.md files in any directory are included as the page for that directory. 5 DISASTER_RECOVERY.md and other root-level .md files are included as top-level pages. 6 PLAN.md files are excluded (internal planning docs, not committed). 7 .pages files are copied so mkdocs-awesome-pages-plugin picks up nav labels. 8 9 Run by mkdocs-gen-files during `mkdocs serve` / `mkdocs build`. 10 """ 11 12 from pathlib import Path 13 14 import mkdocs_gen_files 15 16 ROOT = Path(".") 17 EXCLUDE_DIRS = {".git", ".github", "docs", "site", "security-policies"} 18 19 20 def is_excluded(path: Path) -> bool: 21 return any(part in EXCLUDE_DIRS for part in path.parts) 22 23 24 # Copy markdown files into the virtual docs directory 25 for md_path in sorted(ROOT.rglob("*.md")): 26 if is_excluded(md_path): 27 continue 28 if md_path.name == "PLAN.md": 29 continue 30 with mkdocs_gen_files.open(str(md_path), "w") as f: 31 f.write(md_path.read_text()) 32 33 # Copy .pages files so mkdocs-awesome-pages-plugin picks up nav labels and ordering 34 for pages_path in sorted(ROOT.rglob(".pages")): 35 if is_excluded(pages_path): 36 continue 37 with mkdocs_gen_files.open(str(pages_path), "w") as f: 38 f.write(pages_path.read_text())