mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-29 20:05:25 +08:00
fix: preserve docs hierarchy in GitHub Wiki (#106)
Co-authored-by: dadachann <[email protected]>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path, PurePosixPath
|
||||
@@ -68,6 +69,66 @@ description: "ignored"
|
||||
self.assertIn("[zh Guide](zh-guide)", (output / "_Sidebar.md").read_text())
|
||||
self.assertTrue((output / "Home.md").is_file())
|
||||
|
||||
def test_sidebar_follows_docs_navigation_hierarchy(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
documents = {
|
||||
"zh/insight/guide.mdx": "---\ntitle: 中文首页\n---\nContent\n",
|
||||
"zh/usage/models/readme.mdx": "---\ntitle: 模型配置\n---\nContent\n",
|
||||
"zh/usage/models/custom.mdx": "---\ntitle: 自定义模型\n---\nContent\n",
|
||||
"en/insight/guide.mdx": "---\ntitle: English Home\n---\nContent\n",
|
||||
"ja/insight/guide.mdx": "---\ntitle: 日本語ホーム\n---\nContent\n",
|
||||
}
|
||||
for relative, content in documents.items():
|
||||
path = root / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content, encoding="utf-8")
|
||||
(root / "docs.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"navigation": {
|
||||
"languages": [
|
||||
{
|
||||
"language": "cn",
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "指南",
|
||||
"groups": [
|
||||
{"group": "快速开始", "pages": ["zh/insight/guide"]},
|
||||
{
|
||||
"group": "配置 AI",
|
||||
"pages": [
|
||||
"zh/usage/models/readme",
|
||||
{
|
||||
"group": "模型供应商",
|
||||
"pages": ["zh/usage/models/custom"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
output = root / "out"
|
||||
wiki.build(root, output)
|
||||
sidebar = (output / "_Sidebar.md").read_text(encoding="utf-8")
|
||||
|
||||
self.assertIn("<summary><strong>简体中文</strong></summary>", sidebar)
|
||||
self.assertIn("<summary>指南</summary>", sidebar)
|
||||
self.assertIn("- **快速开始**", sidebar)
|
||||
self.assertIn(" - [中文首页](zh-insight-guide)", sidebar)
|
||||
self.assertIn(" - **模型供应商**", sidebar)
|
||||
self.assertIn(" - [自定义模型](zh-usage-models-custom)", sidebar)
|
||||
self.assertLess(sidebar.index("中文首页"), sidebar.index("模型配置"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user