mitmproxy/docs/scripts/api-render.py

72 lines
1.7 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.
2022-05-15 17:16:19 +00:00
pdoc.render_helpers.formatter.cssclass = "chroma pdoc-code"
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",
"mitmproxy.dns",
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-09-04 15:03:26 +00:00
"mitmproxy.proxy.context",
2021-02-04 21:52:28 +00:00
"mitmproxy.proxy.server_hooks",
2021-02-02 22:34:26 +00:00
"mitmproxy.tcp",
2021-09-04 15:03:26 +00:00
"mitmproxy.tls",
2021-02-02 22:34:26 +00:00
"mitmproxy.websocket",
2021-02-04 21:52:28 +00:00
here / ".." / "src" / "generated" / "events.py",
2021-02-02 22:34:26 +00:00
]
2022-04-26 11:53:35 +00:00
pdoc.pdoc(*modules, output_directory=here / ".." / "src" / "generated" / "api")
2021-02-02 22:34:26 +00:00
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"
2022-04-26 11:53:35 +00:00
(api_content / f"{module}.md").write_text(
textwrap.dedent(
f"""
2021-02-09 00:05:02 +00:00
---
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}" >}}}}
2022-04-26 11:53:35 +00:00
"""
)
)
2021-02-04 21:52:28 +00:00
(here / ".." / "src" / "content" / "addons-api.md").touch()