gen_doc_stubs.py
1 # Generate virtual doc files for the mkdocs site. 2 # You can also run this script directly to actually write out those files, as a preview. 3 4 import mkdocs_gen_files 5 6 # Get the documentation root object 7 root = mkdocs_gen_files.config["plugins"]["mkdocstrings"].get_handler("crystal").collector.root 8 9 # For each type (e.g. "Foo::Bar") 10 for typ in root.walk_types(): 11 # Use the file name "Foo/Bar/index.md" 12 filename = "/".join(typ.abs_id.split("::") + ["index.md"]) 13 # Make a file with the content "# ::: Foo::Bar\n" 14 with mkdocs_gen_files.open(filename, "w") as f: 15 print(f"# ::: {typ.abs_id}", file=f) 16 17 # Link to the type itself when clicking the "edit" button on the page. 18 if typ.locations: 19 mkdocs_gen_files.set_edit_path(filename, typ.locations[0].url)