Skip to content

Commit 10fb77a

Browse files
committed
Recommend new features for generating stubs
1 parent a874f7b commit 10fb77a

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

docs/quickstart/migrate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ But if you make this change by itself, MkDocs will no longer be able to group th
123123
So the navigation now has to be specified fully explicitly. As we've been generating the stub files, let's also generate the nav file itself. The file `docs/gen_doc_stubs.py` will gain these additions:
124124

125125
???+ example "docs/gen_doc_stubs.py"
126-
```python hl_lines="10 15 21-22"
126+
```python hl_lines="10 15 25-26"
127127
--8<-- "examples/migrated/docs/gen_doc_stubs_nav.py"
128128
```
129129

examples/migrated/docs/gen_doc_stubs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
for typ in root.walk_types():
1111
# Use the file name "Foo/Bar/index.md"
1212
filename = '/'.join(typ.abs_id.split('::') + ['index.md'])
13-
# Make a file with the content "::: Foo::Bar\n"
13+
# Make a file with the content "# ::: Foo::Bar\n"
1414
with mkdocs_gen_files.open(filename, 'w') as f:
15-
print(f'::: {typ.abs_id}', file=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)

examples/migrated/docs/gen_doc_stubs_nav.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
for typ in root.walk_types():
1414
# Use the file name "Foo/Bar.md"
1515
filename = '/'.join(typ.abs_id.split('::')) + '.md'
16-
# Make a file with the content "::: Foo::Bar\n"
16+
# Make a file with the content "# ::: Foo::Bar\n"
1717
with mkdocs_gen_files.open(filename, 'w') as f:
18-
print(f'::: {typ.abs_id}', file=f)
18+
print(f'# ::: {typ.abs_id}', file=f)
19+
20+
# Link to the type itself when clicking the "edit" button on the page
21+
if typ.locations:
22+
mkdocs_gen_files.set_edit_path(filename, typ.locations[0].url)
1923

2024
# Append to the nav: " * [Bar](Foo/Bar.md)"
2125
indent = ' ' * typ.abs_id.count('::')

0 commit comments

Comments
 (0)