Load document entries from _index.json files.
(framework: str = "", doc_type: str = "", doc_id: str = "")
| 189 | |
| 190 | |
| 191 | def load_entries(framework: str = "", doc_type: str = "", doc_id: str = "") -> list[dict]: |
| 192 | """Load document entries from _index.json files.""" |
| 193 | entries = [] |
| 194 | |
| 195 | framework_dirs = {} |
| 196 | for d in KNOWLEDGE_ROOT.iterdir(): |
| 197 | if d.is_dir() and not d.name.startswith(".") and not d.name == "scripts": |
| 198 | framework_dirs[d.name] = d |
| 199 | |
| 200 | for fw_id, fw_path in framework_dirs.items(): |
| 201 | if framework and fw_id != framework: |
| 202 | continue |
| 203 | |
| 204 | for type_dir in fw_path.iterdir(): |
| 205 | if not type_dir.is_dir(): |
| 206 | if type_dir.name == "_index.json" and fw_id == "_shared": |
| 207 | try: |
| 208 | with open(type_dir, "r", encoding="utf-8") as f: |
| 209 | data = json.load(f) |
| 210 | for entry in data.get("entries", []): |
| 211 | entry["_framework"] = fw_id |
| 212 | entry["_type"] = "standards" |
| 213 | entries.append(entry) |
| 214 | except Exception: |
| 215 | pass |
| 216 | continue |
| 217 | |
| 218 | t_id = type_dir.name |
| 219 | if doc_type and t_id != doc_type: |
| 220 | continue |
| 221 | |
| 222 | index_file = type_dir / "_index.json" |
| 223 | if not index_file.exists(): |
| 224 | continue |
| 225 | |
| 226 | try: |
| 227 | with open(index_file, "r", encoding="utf-8") as f: |
| 228 | data = json.load(f) |
| 229 | except Exception as e: |
| 230 | logger.warning(f"Failed to load {index_file}: {e}") |
| 231 | continue |
| 232 | |
| 233 | for entry in data.get("entries", []): |
| 234 | entry["_framework"] = fw_id |
| 235 | entry["_type"] = t_id |
| 236 | if doc_id and entry.get("id") != doc_id: |
| 237 | continue |
| 238 | entries.append(entry) |
| 239 | |
| 240 | return entries |
| 241 | |
| 242 | |
| 243 | def get_fulltext_path(entry: dict) -> Path: |