diff --git a/paperforge/worker/base_views.py b/paperforge/worker/base_views.py index e54f4e20..228a633c 100644 --- a/paperforge/worker/base_views.py +++ b/paperforge/worker/base_views.py @@ -477,11 +477,22 @@ def ensure_base_views(vault: Path, paths: dict[str, Path], config: dict, force: updated += "\n" + _render_single_pf_view(v) # Check for missing properties (e.g. ocr_redo) - if " ocr_redo:" not in updated and "properties:" in updated: - updated = updated.replace( - " ocr_status:\n displayName: \"OCR Status\"", - " ocr_status:\n displayName: \"OCR Status\"\n ocr_redo:\n displayName: \"重做OCR\"" - ) + if " ocr_redo:" not in updated: + lines = updated.split("\n") + prop_insert_idx = None + for i, line in enumerate(lines): + stripped = line.strip() + if stripped.startswith("ocr_status:") and not stripped.startswith("ocr_status "): + # Find the end of the ocr_status block (next line without leading space or next property) + blk_end = i + 1 + while blk_end < len(lines) and lines[blk_end].startswith(" ") and not lines[blk_end].lstrip().startswith("ocr_"): + blk_end += 1 + prop_insert_idx = blk_end + break + if prop_insert_idx is not None: + lines.insert(prop_insert_idx, " ocr_redo:") + lines.insert(prop_insert_idx + 1, ' displayName: "重做OCR"') + updated = "\n".join(lines) if updated != existing: base_path.write_text(updated, encoding="utf-8") diff --git a/tests/test_base_views.py b/tests/test_base_views.py index ffae1818..7e0e8dc3 100644 --- a/tests/test_base_views.py +++ b/tests/test_base_views.py @@ -262,7 +262,11 @@ views: - file.inFolder("Resources/Literature/骨科") - file.ext == "md" - !zotero_key.isEmpty() -properties: {} +properties: + ocr_status: + displayName: "OCR Status" + deep_reading_status: + displayName: "Deep Reading" views: # PAPERFORGE_VIEW: 控制面板 - type: table