Skip to content

Commit 67bfa57

Browse files
committed
Add feature to automatically generate .pages file
1 parent 30aef8d commit 67bfa57

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/lazydocs/generation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
8383
"""
8484

85+
_MKDOCS_PAGES_TEMPLATE = """title: API Reference
86+
nav:
87+
- Overview: {overview_file}
88+
- ...
89+
"""
90+
8591

8692
def _get_function_signature(
8793
function: Callable,
@@ -193,9 +199,9 @@ def to_md_file(
193199
date=datetime.date.today().strftime("%d %b %Y")
194200
)
195201

202+
print("Writing {}.".format(md_file))
196203
with open(os.path.join(out_path, md_file), "w") as f:
197204
f.write(string)
198-
print("wrote {}.".format(md_file))
199205

200206

201207
def _code_snippet(snippet: str) -> str:
@@ -947,10 +953,18 @@ def generate_docs(
947953
else:
948954
raise Exception(f"Failed to generate markdown for {path}.")
949955

950-
if overview_file:
956+
if overview_file and not stdout_mode:
957+
if not overview_file.endswith(".md"):
958+
overview_file = overview_file + ".md"
959+
951960
to_md_file(
952961
generator.overview2md(),
953962
overview_file,
954963
out_path=output_path,
955964
watermark=watermark,
956965
)
966+
967+
# Write mkdocs pages file
968+
print("Writing mkdocs .pages file.")
969+
with open(os.path.join(output_path, ".pages"), "w") as f:
970+
f.write(_MKDOCS_PAGES_TEMPLATE.format(overview_file=overview_file))

0 commit comments

Comments
 (0)