From b744ca4527c14af2bd5355851fd58aa404b29100 Mon Sep 17 00:00:00 2001 From: Paul Andrey <paul.andrey@inria.fr> Date: Mon, 27 Mar 2023 12:03:22 +0200 Subject: [PATCH] Improve API reference navigation in online docs. --- scripts/gen_docs.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/gen_docs.py b/scripts/gen_docs.py index 0d44806f..89c0a0ec 100644 --- a/scripts/gen_docs.py +++ b/scripts/gen_docs.py @@ -124,6 +124,7 @@ def parse_module( if not key.startswith("_"): pub_mod[key] = parse_module(mod, docdir) # Create files for classes and functions exported from private submodules. + pub_obj = {} for key, obj in module.members.items(): if obj.is_module or obj.module.name in pub_mod or key.startswith("_"): continue @@ -132,11 +133,19 @@ def parse_module( path = os.path.join(docdir, f"{obj.name}.md") with open(path, "w", encoding="utf-8") as file: file.write(f"#`{obj.path}`\n::: {obj.path}") + pub_obj[key] = f"{obj.name}.md" # Write up an overview file based on the '__init__.py' docs. path = os.path.join(docdir, "index.md") with open(path, "w", encoding="utf-8") as file: file.write(f"::: {module.path}") - return f"{module.name}/index.md" + # Write up a literate-nav summary file based on the created files. + index = rf"- [\[{module.name}\]](./index.md)" + index += "".join(f"\n- [{k}](./{pub_obj[k]})" for k in sorted(pub_obj)) + index += "".join(f"\n- [{k}](./{pub_mod[k]})" for k in sorted(pub_mod)) + path = os.path.join(docdir, "SUMMARY.md") + with open(path, "w", encoding="utf-8") as file: + file.write(index) + return f"{module.name}/" if __name__ == "__main__": -- GitLab