Generate VitePress pages for _shared/ sections (iso_iec, imdrf). Returns list of changed files.
(section: str, dry_run: bool = False)
| 905 | |
| 906 | |
| 907 | def generate_shared_section(section: str, dry_run: bool = False) -> list[str]: |
| 908 | """Generate VitePress pages for _shared/ sections (iso_iec, imdrf). |
| 909 | Returns list of changed files.""" |
| 910 | section_dir = ROOT / "_shared" / section |
| 911 | index_path = section_dir / "_index.json" |
| 912 | if not index_path.exists(): |
| 913 | print(f" SKIP: {index_path} not found") |
| 914 | return [] |
| 915 | |
| 916 | index_data = load_json(index_path) |
| 917 | entries = index_data.get("entries", []) |
| 918 | categories = index_data.get("categories") |
| 919 | changed = [] |
| 920 | |
| 921 | section_names = { |
| 922 | "iso_iec": {"en": "ISO/IEC International Standards", "zh": "ISO/IEC 国际标准"}, |
| 923 | "imdrf": {"en": "IMDRF Technical Documents", "zh": "IMDRF 技术文件"}, |
| 924 | } |
| 925 | sec_name = section_names.get(section, {"en": section.upper(), "zh": section.upper()}) |
| 926 | |
| 927 | has_fulltext = {} |
| 928 | for entry in entries: |
| 929 | eid = entry.get("id", "") |
| 930 | ft_path = section_dir / "fulltext" / f"{eid}.md" |
| 931 | has_fulltext[eid] = ft_path.exists() |
| 932 | |
| 933 | for lang in ("zh", "en"): |
| 934 | docs_dir = DOCS_ZH if lang == "zh" else DOCS_EN |
| 935 | idx_path = docs_dir / "shared" / f"{section}.md" |
| 936 | |
| 937 | lines = ["---"] |
| 938 | lines.append(f"title: {_yaml_safe(sec_name[lang])}") |
| 939 | lines.append("---") |
| 940 | lines.append("") |
| 941 | lines.append(f"# {sec_name[lang]}") |
| 942 | lines.append("") |
| 943 | |
| 944 | if categories: |
| 945 | for cat_id, cat_info in categories.items(): |
| 946 | cat_name = cat_info.get("name", {}) |
| 947 | cat_label = cat_name.get(lang, cat_name.get("en", cat_id)) |
| 948 | cat_entries = [e for e in entries if e.get("category") == cat_id] |
| 949 | if not cat_entries: |
| 950 | continue |
| 951 | ft_count = sum(1 for e in cat_entries if has_fulltext.get(e.get("id", ""))) |
| 952 | count_label = f" ({len(cat_entries)})" if len(cat_entries) > 1 else "" |
| 953 | lines.append(f"### [{cat_label}{count_label}](./{section}/{cat_id})") |
| 954 | lines.append("") |
| 955 | |
| 956 | # Also generate per-category sub-pages |
| 957 | for cat_id, cat_info in categories.items(): |
| 958 | cat_name = cat_info.get("name", {}) |
| 959 | cat_label = cat_name.get(lang, cat_name.get("en", cat_id)) |
| 960 | cat_entries = [e for e in entries if e.get("category") == cat_id] |
| 961 | if not cat_entries: |
| 962 | continue |
| 963 | |
| 964 | cat_lines = ["---"] |
no test coverage detected