Build a limited note index under the configured papers directory.
(config: dict[str, Any])
| 292 | |
| 293 | |
| 294 | def build_vault_note_index(config: dict[str, Any]) -> dict[str, Any]: |
| 295 | """Build a limited note index under the configured papers directory.""" |
| 296 | try: |
| 297 | vault_path = configured_obsidian_vault(config) |
| 298 | except Exception: |
| 299 | return {"status": "vault_unavailable", "notes": []} |
| 300 | if vault_path is None: |
| 301 | return {"status": "vault_unavailable", "notes": []} |
| 302 | |
| 303 | papers_dir = str(config.get("papers_dir", "Research/Papers")).strip() or "Research/Papers" |
| 304 | base_dir = (vault_path / Path(papers_dir)).resolve() |
| 305 | try: |
| 306 | base_dir.relative_to(vault_path) |
| 307 | except ValueError: |
| 308 | return {"status": "vault_unavailable", "notes": []} |
| 309 | if not base_dir.exists() or not base_dir.is_dir(): |
| 310 | return {"status": "vault_unavailable", "notes": []} |
| 311 | |
| 312 | notes: list[dict[str, Any]] = [] |
| 313 | for path in sorted(base_dir.glob("**/*.md")): |
| 314 | try: |
| 315 | relative_path = path.relative_to(vault_path) |
| 316 | except ValueError: |
| 317 | continue |
| 318 | try: |
| 319 | text = path.read_text(encoding="utf-8", errors="ignore")[:4096] |
| 320 | except OSError: |
| 321 | text = "" |
| 322 | frontmatter = _frontmatter_fields(text) |
| 323 | if frontmatter is None: |
| 324 | continue |
| 325 | aliases = frontmatter.get("aliases", []) |
| 326 | doi = normalize_whitespace(str(frontmatter.get("doi", ""))) |
| 327 | arxiv_id = normalize_whitespace( |
| 328 | str(frontmatter.get("arxiv_id", "") or frontmatter.get("arxiv", "")) |
| 329 | ) |
| 330 | normalized_arxiv_ids = { |
| 331 | _normalize_arxiv_id(value) |
| 332 | for value in [arxiv_id, doi] |
| 333 | if _normalize_arxiv_id(value) |
| 334 | } |
| 335 | notes.append( |
| 336 | { |
| 337 | "stem": path.stem, |
| 338 | "aliases": aliases if isinstance(aliases, list) else [], |
| 339 | "frontmatter_title": normalize_whitespace(str(frontmatter.get("title", ""))), |
| 340 | "h1_title": _h1_title(text), |
| 341 | "doi": doi, |
| 342 | "doi_norm": _normalize_doi(doi) if doi else "", |
| 343 | "arxiv_id": arxiv_id, |
| 344 | "arxiv_ids": sorted(normalized_arxiv_ids), |
| 345 | "text_keys": [], |
| 346 | "vault_target": path.stem, |
| 347 | "vault_relative_path": str(relative_path), |
| 348 | } |
| 349 | ) |
| 350 | notes[-1]["text_keys"] = _note_text_keys(notes[-1]) |
| 351 | return {"status": "ok", "notes": notes} |
no test coverage detected