Read all .zh.md files in a data directory and extract metadata.
(data_dir: Path, section_key: str)
| 155 | |
| 156 | |
| 157 | def get_doc_entries(data_dir: Path, section_key: str) -> List[dict]: |
| 158 | """Read all .zh.md files in a data directory and extract metadata.""" |
| 159 | entries = [] |
| 160 | if not data_dir.exists(): |
| 161 | return entries |
| 162 | |
| 163 | for md_file in sorted(data_dir.glob("*.zh.md")): |
| 164 | fm = read_front_matter(md_file) |
| 165 | if not fm: |
| 166 | continue |
| 167 | |
| 168 | title_zh = "" |
| 169 | title_val = fm.get("title", {}) |
| 170 | if isinstance(title_val, dict): |
| 171 | title_zh = title_val.get("zh", "") |
| 172 | elif isinstance(title_val, str): |
| 173 | title_zh = title_val |
| 174 | |
| 175 | if not title_zh: |
| 176 | title_zh = md_file.stem.replace("-", " ").replace(".zh", "") |
| 177 | |
| 178 | entries.append({ |
| 179 | "slug": md_file.stem.replace(".zh", ""), |
| 180 | "title_zh": title_zh, |
| 181 | "doc_number": fm.get("document_number", ""), |
| 182 | "effective_date": fm.get("effective_date", ""), |
| 183 | "published_date": fm.get("published_date", ""), |
| 184 | "status": fm.get("status", "active"), |
| 185 | "source_url": fm.get("source_url", ""), |
| 186 | "regulation": fm.get("regulation", ""), |
| 187 | "category": fm.get("category", section_key), |
| 188 | "file": md_file, |
| 189 | }) |
| 190 | |
| 191 | return entries |
| 192 | |
| 193 | |
| 194 | def group_nmpa_guidance(entries: List[dict]) -> Dict[str, List[dict]]: |
no test coverage detected