Skip to content

Commit 623f31b

Browse files
authored
docs: migrate documentation site to zensical (#41)
* build: migrate documentation site to zensical * fix: restore default theme and side navigation * docs: automate API reference generation Signed-off-by: Illustar0 <me@illustar0.com> --------- Signed-off-by: Illustar0 <me@illustar0.com>
1 parent c3222a1 commit 623f31b

10 files changed

Lines changed: 1228 additions & 202 deletions

File tree

.github/workflows/build-docs.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
id: build
3535
run: |
3636
uv sync --extra docs
37-
uv run mkdocs build
37+
uv run python scripts/generate_api_reference.py
38+
uv run zensical build
3839
3940
- name: Upload static files as artifact
4041
id: deployment
@@ -51,4 +52,4 @@ jobs:
5152
steps:
5253
- name: Deploy to GitHub Pages
5354
id: deployment
54-
uses: actions/deploy-pages@v5
55+
uses: actions/deploy-pages@v5

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ with EPortalClient(portal.portal_server_url, bind_address=portal.user_ip) as cli
8686

8787
- 使用文档:<https://illustar0.github.io/ZZU.Py/>
8888
- API 参考:<https://illustar0.github.io/ZZU.Py/reference/api/>
89+
- 文档站点由 `Zensical` 构建
8990

9091
## 开发
9192

9293
项目使用 `uv` 管理环境和命令。
9394

9495
```bash
9596
uv sync --extra develop,docs
97+
uv run python scripts/generate_api_reference.py
98+
uv run zensical serve
99+
uv run zensical build
96100
ruff format zzupy
97101
ruff check zzupy
98102
ty check zzupy

docs/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ with EPortalClient(portal.portal_server_url, bind_address=portal.user_ip) as cli
7979
项目使用 `uv` 管理环境,常用命令:
8080

8181
```bash
82-
uv sync
82+
uv sync --extra docs
83+
uv run python scripts/generate_api_reference.py
84+
uv run zensical serve
85+
uv run zensical build
8386
ruff check
8487
uv build
8588
```

docs/note.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
hide:
3-
- navigation
4-
---
51
# 逆向笔记
62

73
一些在实现 `zzupy` 过程中记录下来的上游接口行为。这里只保留对源码实现有直接帮助的信息。

docs/reference/api.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
---
22
title: API
3-
hide:
4-
- navigation
53
---
64

7-
此页由 `mkdocstrings` 根据源码自动生成,适合在以下场景使用:
5+
<!-- 由 scripts/generate_api_reference.py 自动生成,请勿手动维护模块列表。 -->
6+
7+
此页由 `Zensical` 配合 `mkdocstrings` 根据源码自动生成,适合在以下场景使用:
88

99
- 查看公开模块和导出符号
1010
- 确认方法签名、参数名和返回值
1111
- 查询 Pydantic 模型字段
1212

13-
如果你更关注接入步骤和调用示例,优先阅读 `Usage`
14-
15-
::: zzupy
16-
options:
17-
show_submodules: true
13+
如果你更关注接入步骤和调用示例,优先阅读 `Usage`

mkdocs.yml

Lines changed: 0 additions & 175 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,8 @@ develop = [
2727
]
2828

2929
docs = [
30-
"markdown-callouts>=0.4.0",
31-
"markdown-exec>=1.11.0",
32-
"mkdocs-git-revision-date-localized-plugin>=1.4.7",
33-
"mkdocs-llmstxt>=0.3.1",
34-
"mkdocs-minify-plugin>=0.8.0",
35-
"mkdocs-redirects>=1.2.2",
36-
"mkdocs-section-index>=0.3.10",
37-
"mkdocs>=1.6.1",
38-
"mkdocs-material>=9.6.20",
39-
"mkdocstrings>=0.30.0",
4030
"mkdocstrings[python]>=0.30.0",
41-
"jieba>=0.42.1",
42-
"mkdocs-include-markdown-plugin>=7.1.7",
31+
"zensical>=0.0.11",
4332
]
4433

4534

scripts/generate_api_reference.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
6+
ROOT = Path(__file__).resolve().parents[1]
7+
PACKAGE_DIR = ROOT / "zzupy"
8+
OUTPUT = ROOT / "docs" / "reference" / "api.md"
9+
10+
11+
def iter_modules() -> list[str]:
12+
modules: list[str] = []
13+
14+
for path in sorted(PACKAGE_DIR.rglob("*.py")):
15+
relative = path.relative_to(ROOT).with_suffix("")
16+
parts = list(relative.parts)
17+
18+
if parts[-1] == "__main__":
19+
continue
20+
if parts[-1] == "__init__":
21+
parts = parts[:-1]
22+
23+
if not parts:
24+
continue
25+
26+
modules.append(".".join(parts))
27+
28+
return modules
29+
30+
31+
def heading_level(module: str) -> str:
32+
depth = module.count(".")
33+
return "#" * min(depth + 2, 6)
34+
35+
36+
def build_content(modules: list[str]) -> str:
37+
lines = [
38+
"---",
39+
"title: API",
40+
"---",
41+
"",
42+
"<!-- 由 scripts/generate_api_reference.py 自动生成,请勿手动维护模块列表。 -->",
43+
"",
44+
"此页由 `Zensical` 配合 `mkdocstrings` 根据源码自动生成,适合在以下场景使用:",
45+
"",
46+
"- 查看公开模块和导出符号",
47+
"- 确认方法签名、参数名和返回值",
48+
"- 查询 Pydantic 模型字段",
49+
"",
50+
"如果你更关注接入步骤和调用示例,优先阅读 `Usage`。",
51+
"",
52+
]
53+
54+
for module in modules:
55+
lines.extend(
56+
[
57+
f"{heading_level(module)} `{module}`",
58+
"",
59+
f"::: {module}",
60+
"",
61+
]
62+
)
63+
64+
return "\n".join(lines)
65+
66+
67+
def main() -> None:
68+
modules = iter_modules()
69+
OUTPUT.write_text(build_content(modules), encoding="utf-8")
70+
71+
72+
if __name__ == "__main__":
73+
main()

0 commit comments

Comments
 (0)