Skip to content

Commit bfbdde7

Browse files
Fix MkDocs API reference generation and navigation. (#8)
The gen-files script was creating API stub pages, but static nav in mkdocs.yml excluded them and paths used reference/foo.md instead of reference/pdwidgets/foo/index.md, breaking reference/SUMMARY.md links. Remove static nav in favor of literate-nav from docs/SUMMARY.md, add API Reference section, rewrite the gen script following the mkdocstrings recipe, and enable symbol type headings in mkdocstrings. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Brad Barnett <bdbarnett@users.noreply.github.com>
1 parent 8d8b3be commit bfbdde7

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

docs/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
docs/SUMMARY.md
1+
* [Home](index.md)
2+
* [Getting started](getting-started.md)
3+
* [Installation](installation.md)
4+
* [Publishing](publishing.md)
5+
* [API Reference](reference/)

mkdocs.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ plugins:
4141
paths: [src]
4242
options:
4343
show_source: false
44+
show_root_heading: true
45+
show_symbol_type_heading: true
46+
show_symbol_type_toc: true
4447
docstring_style: google
4548
merge_init_into_class: true
4649
filters:
4750
- "!^_"
48-
49-
nav:
50-
- Home: index.md
51-
- Getting started: getting-started.md
52-
- Installation: installation.md
53-
- Publishing: publishing.md

scripts/mkdocs_gen_ref_pages.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
"""Generate mkdocstrings API reference stubs for pdwidgets."""
1+
"""Generate mkdocstrings API reference stubs and navigation for pdwidgets."""
22

33
from pathlib import Path
44

55
import mkdocs_gen_files
66

77
nav = mkdocs_gen_files.Nav()
88
root = Path(__file__).parent.parent
9-
src = root / "src" / "pdwidgets"
9+
src = root / "src"
10+
reference = Path("reference")
1011

11-
for path in sorted(src.rglob("*.py")):
12+
for path in sorted((src / "pdwidgets").rglob("*.py")):
1213
if path.name.startswith("_") and path.name != "__init__.py":
1314
continue
14-
rel = path.relative_to(src).with_suffix("")
15-
parts = list(rel.parts)
15+
module_path = path.relative_to(src).with_suffix("")
16+
doc_path = module_path.with_suffix(".md")
17+
full_doc_path = reference / doc_path
18+
19+
parts = tuple(module_path.parts)
20+
1621
if parts[-1] == "__init__":
1722
parts = parts[:-1]
18-
doc_path = Path("reference", *parts).with_suffix(".md")
23+
doc_path = doc_path.with_name("index.md")
24+
full_doc_path = full_doc_path.with_name("index.md")
25+
elif parts[-1] == "__main__":
26+
continue
27+
1928
nav[parts] = doc_path.as_posix()
20-
with mkdocs_gen_files.open(doc_path, "w") as fd:
21-
ident = ".".join(["pdwidgets", *parts])
29+
30+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
31+
ident = ".".join(parts)
2232
fd.write(f"::: {ident}\n")
23-
mkdocs_gen_files.set_edit_path(doc_path, path.relative_to(root))
33+
34+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))
2435

2536
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
2637
nav_file.writelines(nav.build_literate_nav())

0 commit comments

Comments
 (0)