Generate docs/.vitepress/sidebar.json with dynamic sidebar items. VitePress uses longest-prefix matching for sidebar: /zh/nmpa/ -> static sidebar in config.ts (overview pages) /zh/nmpa/guidance/ -> dynamic grouped sidebar (guidance sub-pages) /zh/nmpa/regulatio
(all_section_entries: Dict[str, List[dict]], repo_root: Path, dry_run: bool = False)
| 451 | |
| 452 | |
| 453 | def generate_sidebar_json(all_section_entries: Dict[str, List[dict]], repo_root: Path, dry_run: bool = False) -> None: |
| 454 | """ |
| 455 | Generate docs/.vitepress/sidebar.json with dynamic sidebar items. |
| 456 | |
| 457 | VitePress uses longest-prefix matching for sidebar: |
| 458 | /zh/nmpa/ -> static sidebar in config.ts (overview pages) |
| 459 | /zh/nmpa/guidance/ -> dynamic grouped sidebar (guidance sub-pages) |
| 460 | /zh/nmpa/regulations/ -> dynamic sidebar (regulation sub-pages) |
| 461 | /zh/insights/ -> dynamic sidebar (insights pages) |
| 462 | """ |
| 463 | sidebar: Dict[str, list] = {} |
| 464 | |
| 465 | en_sidebar: Dict[str, list] = {} |
| 466 | |
| 467 | for section_key, entries in all_section_entries.items(): |
| 468 | items = [] |
| 469 | for entry in entries: |
| 470 | slug = unquote(entry["slug"]) |
| 471 | items.append({ |
| 472 | "text": entry["title_zh"], |
| 473 | "link": f"/zh/{section_key}/{slug}", |
| 474 | }) |
| 475 | |
| 476 | # Build English sidebar items for this section |
| 477 | en_items = [] |
| 478 | en_entries = get_en_entries(entries, repo_root) |
| 479 | for en_entry in en_entries: |
| 480 | slug = unquote(en_entry["slug"]) |
| 481 | en_items.append({ |
| 482 | "text": en_entry["title_en"], |
| 483 | "link": f"/en/{section_key}/{slug}", |
| 484 | }) |
| 485 | |
| 486 | if section_key == "nmpa/guidance": |
| 487 | groups = group_nmpa_guidance(entries) |
| 488 | sidebar_items = [ |
| 489 | {"text": "<- NMPA 概览", "link": "/zh/nmpa/"}, |
| 490 | {"text": "指导原则索引", "link": "/zh/nmpa/guidance"}, |
| 491 | ] |
| 492 | for group_name, group_entries in groups.items(): |
| 493 | if not group_entries: |
| 494 | continue |
| 495 | children = [] |
| 496 | for e in sorted(group_entries, key=lambda x: x["title_zh"]): |
| 497 | s = unquote(e["slug"]) |
| 498 | children.append({"text": e["title_zh"], "link": f"/zh/nmpa/guidance/{s}"}) |
| 499 | sidebar_items.append({ |
| 500 | "text": f"{group_name} ({len(group_entries)})", |
| 501 | "collapsed": True, |
| 502 | "items": children, |
| 503 | }) |
| 504 | sidebar["/zh/nmpa/guidance/"] = sidebar_items |
| 505 | |
| 506 | elif section_key == "nmpa/regulations": |
| 507 | sorted_items = sorted(items, key=lambda x: x["text"]) |
| 508 | sidebar["/zh/nmpa/regulations/"] = [ |
| 509 | {"text": "<- NMPA 概览", "link": "/zh/nmpa/"}, |
| 510 | {"text": "法规规章索引", "link": "/zh/nmpa/regulations"}, |
no test coverage detected