Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd4a839

Browse files
committedApr 29, 2025·
working on nav
1 parent fe4a6ae commit fd4a839

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed
 

‎docs/scripts/gen_api_pages.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,44 @@
77

88
import mkdocs_gen_files
99

10-
api_nav = mkdocs_gen_files.Nav()
10+
gen_nav = mkdocs_gen_files.Nav()
1111

1212
repo_root = Path(__file__).parent.parent.parent
13-
src = repo_root / "src"
1413

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)
14+
def gen_pkg_docs():
15+
src = repo_root / "src"
16+
# pkg_src = repo_root / "src" / pkg
17+
for path in sorted(src.rglob("*.py")):
18+
module_path = path.relative_to(src).with_suffix("")
19+
doc_path = path.relative_to(src).with_suffix(".md")
20+
full_doc_path = Path("gen_reference", doc_path)
1921

20-
parts = tuple(module_path.parts)
22+
parts = tuple(module_path.parts)
2123

22-
if parts[-1] == "__init__":
23-
parts = parts[:-1]
24-
elif parts[-1] == "__main__":
25-
continue
24+
if parts[-1] == "__init__":
25+
parts = parts[:-1]
26+
doc_path = doc_path.with_name("index.md")
27+
full_doc_path = full_doc_path.with_name("index.md")
28+
elif parts[-1] == "__main__":
29+
continue
2630

27-
api_nav[parts] = doc_path.as_posix()
31+
gen_nav[parts] = doc_path.as_posix()
2832

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+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
34+
identifier = ".".join(parts)
35+
print("::: " + identifier, file=fd)
36+
# TODO: add the options I want. See my old manual api*.md files.
3337

34-
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(repo_root))
38+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(repo_root))
3539

3640

37-
with mkdocs_gen_files.open("gen_reference/API_NAV.md", "w") as nav_file:
38-
nav_file.writelines(api_nav.build_literate_nav())
41+
with mkdocs_gen_files.open(f"gen_reference/GEN_NAV.md", "w") as nav_file:
42+
nav_file.writelines(gen_nav.build_literate_nav())
43+
44+
# FIXME: The current top level nav between root level packages is awkward.
45+
# The nav bar on the left is hiding "planet_auth" and only showing "planet_auth_utils".
46+
gen_pkg_docs()
47+
48+
# TODO - separate nav for better doc site navigation?
49+
# gen_pkg_docs("planet_auth")
50+
# gen_pkg_docs("planet_auth_utils")

‎mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ plugins:
4848
scripts:
4949
- docs/scripts/gen_api_pages.py
5050
- literate-nav:
51-
nav_file: 'API_NAV.md'
51+
nav_file: 'GEN_NAV.md'
52+
- section-index
5253
- macros:
5354
include_dir: 'docs/examples'
5455
on_error_fail: true

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ docs = [
5353
"mkdocs-linkcheck",
5454
"mkdocs-material == 9.6.12", # Upgrades may interact with docs/custom_theme
5555
"mkdocs-macros-plugin",
56+
"mkdocs-section-index",
5657
]
5758
examples = [
5859
"flask",

0 commit comments

Comments
 (0)
Please sign in to comment.