Files
Manlink_Doc/source/_scripts/gen_index.py
T
yuysh 311ca6702d
Build and Deploy Sphinx Docs / Build Documentation (push) Successful in 2m12s
Init Commit
2025-08-25 10:51:31 +08:00

24 lines
829 B
Python

from pathlib import Path
HARDWARE_INDEX = Path(__file__).parent.parent / "hardware/index.md"
HARDWARE_DIR = Path(__file__).parent.parent / "hardware"
def generate_hardware_index():
boards = []
for board_dir in HARDWARE_DIR.iterdir():
if board_dir.is_dir() and (board_dir / "index.md").exists():
# 关键修改:使用标准Sphinx路径格式
boards.append(f"{board_dir.name}/index") # 移除了./和空格
toctree_content = (
"# 硬件文档中心\n\n"
"```{toctree}\n"
":maxdepth: 2\n"
":caption: 板卡列表\n"
":glob:\n\n" + # 添加glob指令增强容错性
"\n".join(sorted(boards)) + "\n```")
HARDWARE_INDEX.write_text(toctree_content, encoding="utf-8")
if __name__ == "__main__":
generate_hardware_index()