Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* [Getting started](getting-started.md)
* [Installation](installation.md)
* [Publishing](publishing.md)
* [API Reference](reference/)
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Documentation for the **palettes** package — color palettes for pydisplay grap

- [Getting started](getting-started.md)
- [Installation](installation.md)
- [API Reference](reference/palettes/index.md)
- [pydisplay documentation](https://pydisplay.readthedocs.io)
- [Browser demos](https://pydevices.github.io/pydisplay/pyscript/)
9 changes: 3 additions & 6 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ plugins:
paths: [src]
options:
show_source: false
show_root_heading: true
show_symbol_type_heading: true
show_symbol_type_toc: true
docstring_style: google
merge_init_into_class: true
filters:
- "!^_"

nav:
- Home: index.md
- Getting started: getting-started.md
- Installation: installation.md
- Publishing: publishing.md
29 changes: 20 additions & 9 deletions scripts/mkdocs_gen_ref_pages.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
"""Generate mkdocstrings API reference stubs for palettes."""
"""Generate mkdocstrings API reference stubs and navigation for palettes."""

from pathlib import Path

import mkdocs_gen_files

nav = mkdocs_gen_files.Nav()
root = Path(__file__).parent.parent
src = root / "src" / "palettes"
src = root / "src"
reference = Path("reference")

for path in sorted(src.rglob("*.py")):
for path in sorted((src / "palettes").rglob("*.py")):
if path.name.startswith("_") and path.name != "__init__.py":
continue
rel = path.relative_to(src).with_suffix("")
parts = list(rel.parts)
module_path = path.relative_to(src).with_suffix("")
doc_path = module_path.with_suffix(".md")
full_doc_path = reference / doc_path

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = Path("reference", *parts).with_suffix(".md")
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue

nav[parts] = doc_path.as_posix()
with mkdocs_gen_files.open(doc_path, "w") as fd:
ident = ".".join(["palettes", *parts])

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(f"::: {ident}\n")
mkdocs_gen_files.set_edit_path(doc_path, path.relative_to(root))

mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))

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