Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
docs: generate hierarchical per-module API reference pages#2103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Generate the code reference pages and navigation.""" | ||
| from pathlib import Path | ||
| import mkdocs_gen_files | ||
| nav = mkdocs_gen_files.Nav() | ||
| root = Path(__file__).parent.parent.parent | ||
| src = root / "src" | ||
| for path in sorted(src.rglob("*.py")): | ||
| module_path = path.relative_to(src).with_suffix("") | ||
| doc_path = path.relative_to(src).with_suffix(".md") | ||
| full_doc_path = Path("api", doc_path) | ||
| parts = tuple(module_path.parts) | ||
| if parts[-1] == "__init__": | ||
| parts = parts[:-1] | ||
| doc_path = doc_path.with_name("index.md") | ||
| full_doc_path = full_doc_path.with_name("index.md") | ||
| elif parts[-1].startswith("_"): | ||
| continue | ||
| nav[parts] = doc_path.as_posix() | ||
| with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
| ident = ".".join(parts) | ||
| fd.write(f"::: {ident}") | ||
| mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root)) | ||
| with mkdocs_gen_files.open("api/SUMMARY.md", "w") as nav_file: | ||
| nav_file.writelines(nav.build_literate_nav()) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.