Ensure sections have safe unique IDs and an overview section first.
(sections: list, lang: str)
| 690 | |
| 691 | |
| 692 | def normalize_sections(sections: list, lang: str) -> list: |
| 693 | """Ensure sections have safe unique IDs and an overview section first.""" |
| 694 | overview_name = pick_text(lang, "架构总览", "Architecture Overview") |
| 695 | normalized = [{"id": "overview", "name": overview_name, "communities": []}] |
| 696 | used = {"overview", "hyperedges", "stats"} |
| 697 | |
| 698 | for index, raw in enumerate(sections or [], 1): |
| 699 | if not isinstance(raw, dict): |
| 700 | continue |
| 701 | raw_id = str(raw.get("id") or raw.get("key") or raw.get("name") or f"section-{index}") |
| 702 | raw_name = str(raw.get("name") or raw.get("label") or raw_id) |
| 703 | if raw_id.lower() == "overview": |
| 704 | normalized[0]["name"] = raw_name or overview_name |
| 705 | continue |
| 706 | |
| 707 | sid = html_anchor_id(raw_id, f"section-{index}", used) |
| 708 | normalized.append({ |
| 709 | "id": sid, |
| 710 | "name": raw_name, |
| 711 | "communities": normalize_communities(raw.get("communities", raw.get("community"))), |
| 712 | }) |
| 713 | return normalized |
| 714 | |
| 715 | |
| 716 | def label_for_community(cid: str, labels: dict, nodes: list, lang: str) -> str: |
no test coverage detected