判断文件是否需要(重新)处理。 - .md:检查是否已加锚点 && outline.json 是否存在 - 其他:检查 .md 是否存在、mtime、outline.json 是否存在
(source: Path, force: bool)
| 106 | |
| 107 | |
| 108 | def should_convert(source: Path, force: bool) -> bool: |
| 109 | """判断文件是否需要(重新)处理。 |
| 110 | - .md:检查是否已加锚点 && outline.json 是否存在 |
| 111 | - 其他:检查 .md 是否存在、mtime、outline.json 是否存在 |
| 112 | """ |
| 113 | if force: |
| 114 | return True |
| 115 | is_md = source.suffix.lower() == ".md" |
| 116 | target_md = source if is_md else source.with_suffix(".md") |
| 117 | target_outline = source.with_suffix(".outline.json") |
| 118 | if not target_md.exists(): |
| 119 | return True |
| 120 | if not target_outline.exists(): |
| 121 | return True |
| 122 | if not is_md: |
| 123 | # 非 .md:原文件 mtime 新于派生 .md → 重转 |
| 124 | if source.stat().st_mtime > target_md.stat().st_mtime: |
| 125 | return True |
| 126 | else: |
| 127 | # .md:检查是否已加锚点 |
| 128 | try: |
| 129 | if not has_anchors(source.read_text(encoding="utf-8")): |
| 130 | return True |
| 131 | except Exception: |
| 132 | return True |
| 133 | return False |
| 134 | |
| 135 | |
| 136 | def collect_files(scan_dir: Path, extensions: set[str] | None) -> list[Path]: |