|
4 | 4 | import mkdocs_gen_files |
5 | 5 |
|
6 | 6 | # Get the documentation root object |
7 | | -root = mkdocs_gen_files.config['plugins']['mkdocstrings'].get_handler('crystal').collector.root |
| 7 | +root = mkdocs_gen_files.config["plugins"]["mkdocstrings"].get_handler("crystal").collector.root |
8 | 8 |
|
9 | | -# Start a navigation file (to be filled as we go along) |
10 | | -nav = mkdocs_gen_files.open('SUMMARY.md', 'a') |
| 9 | +# Start a navigation collection (to be filled as we go along) |
| 10 | +nav = mkdocs_gen_files.Nav() |
11 | 11 |
|
12 | 12 | # For each type (e.g. "Foo::Bar") |
13 | 13 | for typ in root.walk_types(): |
14 | 14 | # Use the file name "Foo/Bar.md" |
15 | | - filename = '/'.join(typ.abs_id.split('::')) + '.md' |
| 15 | + filename = "/".join(typ.abs_id.split("::")) + ".md" |
16 | 16 | # Make a file with the content "# ::: Foo::Bar\n" |
17 | | - with mkdocs_gen_files.open(filename, 'w') as f: |
18 | | - print(f'# ::: {typ.abs_id}', file=f) |
| 17 | + with mkdocs_gen_files.open(filename, "w") as f: |
| 18 | + print(f"# ::: {typ.abs_id}", file=f) |
19 | 19 |
|
20 | 20 | # Link to the type itself when clicking the "edit" button on the page |
21 | 21 | if typ.locations: |
22 | 22 | mkdocs_gen_files.set_edit_path(filename, typ.locations[0].url) |
23 | 23 |
|
24 | 24 | # Append to the nav: " * [Bar](Foo/Bar.md)" |
25 | | - indent = ' ' * typ.abs_id.count('::') |
26 | | - print(indent + f'* [{typ.name}]({filename})', file=nav) |
| 25 | + nav[typ.abs_id.split("::")] = filename |
| 26 | + |
| 27 | +# Append the nav to a "literate nav" file |
| 28 | +with mkdocs_gen_files.open("SUMMARY.md", "a") as nav_file: |
| 29 | + nav_file.writelines(nav.build_literate_nav()) |
0 commit comments