Skip to content

Commit fe4a6ae

Browse files
experiments in generated API nav files.
1 parent 4f3f8eb commit fe4a6ae

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed
File renamed without changes.
File renamed without changes.

docs/scripts/gen_api_pages.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Generate the code reference pages."""
2+
3+
# Recipe to break up API docs into multiple pages from
4+
# https://mkdocstrings.github.io/recipes/#automatic-code-reference-pages
5+
6+
from pathlib import Path
7+
8+
import mkdocs_gen_files
9+
10+
api_nav = mkdocs_gen_files.Nav()
11+
12+
repo_root = Path(__file__).parent.parent.parent
13+
src = repo_root / "src"
14+
15+
for path in sorted(src.rglob("*.py")):
16+
module_path = path.relative_to(src).with_suffix("")
17+
doc_path = path.relative_to(src).with_suffix(".md")
18+
full_doc_path = Path("gen_reference", doc_path)
19+
20+
parts = tuple(module_path.parts)
21+
22+
if parts[-1] == "__init__":
23+
parts = parts[:-1]
24+
elif parts[-1] == "__main__":
25+
continue
26+
27+
api_nav[parts] = doc_path.as_posix()
28+
29+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
30+
identifier = ".".join(parts)
31+
print("::: " + identifier, file=fd)
32+
# TODO: add the options I want. See my old manual api*.md files.
33+
34+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(repo_root))
35+
36+
37+
with mkdocs_gen_files.open("gen_reference/API_NAV.md", "w") as nav_file:
38+
nav_file.writelines(api_nav.build_literate_nav())

mkdocs.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ hooks:
4444

4545
plugins:
4646
- search:
47+
- gen-files:
48+
scripts:
49+
- docs/scripts/gen_api_pages.py
50+
- literate-nav:
51+
nav_file: 'API_NAV.md'
4752
- macros:
4853
include_dir: 'docs/examples'
4954
on_error_fail: true
@@ -77,9 +82,10 @@ nav:
7782
- Overview: 'library-overview.md'
7883
- Auth Client Configuration: 'configuration.md'
7984
- Built-in Injection: 'built-ins.md'
80-
- API Reference:
81-
- Planet Auth: 'api-planet-auth.md'
82-
- Planet Auth Utils: 'api-planet-auth-utils.md'
85+
# - API Reference:
86+
# - Planet Auth: 'api-planet-auth.md'
87+
# - Planet Auth Utils: 'api-planet-auth-utils.md'
88+
- API Reference: gen_reference/
8389
- Examples:
8490
- Installation: 'examples-installation.md'
8591
- CLI: 'examples-cli.md'

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ docs = [
4848
# https://github.com/mkdocstrings/mkdocstrings/discussions/743
4949
"mkdocstrings[python] == 0.28.3",
5050
"mkdocs-click",
51+
"mkdocs-gen-files",
52+
"mkdocs-literate-nav",
53+
"mkdocs-linkcheck",
5154
"mkdocs-material == 9.6.12", # Upgrades may interact with docs/custom_theme
5255
"mkdocs-macros-plugin",
53-
"mkdocs-linkcheck",
54-
# "linkcheckmd",
5556
]
5657
examples = [
5758
"flask",

0 commit comments

Comments
 (0)