mitmproxy/docs/scripts/api-render.py

68 lines
1.6 KiB
Python
Raw Normal View History

2021-02-02 22:34:26 +00:00
#!/usr/bin/env python3
import os
import shutil
2021-02-09 00:05:02 +00:00
import textwrap
2021-02-02 22:34:26 +00:00
from pathlib import Path
2021-02-04 21:52:28 +00:00
import pdoc.render_helpers
2021-02-02 22:34:26 +00:00
here = Path(__file__).parent
if os.environ.get("DOCS_ARCHIVE", False):
edit_url_map = {}
else:
edit_url_map = {
2021-03-16 15:17:27 +00:00
"mitmproxy": "https://github.com/mitmproxy/mitmproxy/blob/main/mitmproxy/",
2021-02-02 22:34:26 +00:00
}
pdoc.render.configure(
template_directory=here / "pdoc-template",
edit_url_map=edit_url_map,
)
2021-02-04 21:52:28 +00:00
# We can't configure Hugo, but we can configure pdoc.
pdoc.render_helpers.formatter.cssclass = "chroma"
2021-02-02 22:34:26 +00:00
modules = [
2021-02-04 21:52:28 +00:00
"mitmproxy.addonmanager",
"mitmproxy.certs",
2021-02-05 21:04:45 +00:00
"mitmproxy.connection",
"mitmproxy.coretypes.multidict",
2021-02-02 22:34:26 +00:00
"mitmproxy.flow",
2021-02-04 21:52:28 +00:00
"mitmproxy.http",
2021-02-09 00:05:02 +00:00
"mitmproxy.net.server_spec",
2021-02-04 21:52:28 +00:00
"mitmproxy.proxy.server_hooks",
2021-02-02 22:34:26 +00:00
"mitmproxy.tcp",
"mitmproxy.websocket",
2021-02-04 21:52:28 +00:00
here / ".." / "src" / "generated" / "events.py",
2021-02-02 22:34:26 +00:00
]
pdoc.pdoc(
*modules,
output_directory=here / ".." / "src" / "generated" / "api"
)
api_content = here / ".." / "src" / "content" / "api"
if api_content.exists():
shutil.rmtree(api_content)
api_content.mkdir()
for module in modules:
if isinstance(module, Path):
continue
2021-02-04 21:52:28 +00:00
filename = f"api/{module.replace('.', '/')}.html"
2021-02-09 00:05:02 +00:00
(api_content / f"{module}.md").write_text(textwrap.dedent(f"""
---
title: "{module}"
url: "{filename}"
2021-02-02 22:34:26 +00:00
2021-02-09 00:05:02 +00:00
menu:
addons:
parent: 'Event Hooks & API'
---
2021-02-02 22:34:26 +00:00
2021-02-09 00:05:02 +00:00
{{{{< readfile file="/generated/{filename}" >}}}}
"""))
2021-02-04 21:52:28 +00:00
(here / ".." / "src" / "content" / "addons-api.md").touch()