MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / sync_en_content_to_docs

Function sync_en_content_to_docs

scripts/generate_docs_index.py:352–401  ·  view source on GitHub ↗

Copy data layer *.en.md files into docs/en/ / for VitePress rendering. Strips the .en suffix so the route becomes /en/ / . Only syncs files that have substantive English content (not just frontmatter/placeholders). Returns count of files synced.

(section_key: str, entries: List[dict], repo_root: Path, dry_run: bool = False)

Source from the content-addressed store, hash-verified

350
351
352def sync_en_content_to_docs(section_key: str, entries: List[dict], repo_root: Path, dry_run: bool = False) -> int:
353 """
354 Copy data layer *.en.md files into docs/en/<section_key>/ for VitePress rendering.
355 Strips the .en suffix so the route becomes /en/<section_key>/<slug>.
356 Only syncs files that have substantive English content (not just frontmatter/placeholders).
357 Returns count of files synced.
358 """
359 synced = 0
360 dest_dir = repo_root / "docs" / "en" / section_key
361 if not dry_run:
362 dest_dir.mkdir(parents=True, exist_ok=True)
363
364 for entry in entries:
365 src_file: Path = entry["file"]
366 # Derive the .en.md path from the .zh.md path
367 en_src = src_file.parent / src_file.name.replace(".zh.md", ".en.md")
368 if not en_src.exists():
369 continue
370
371 content = en_src.read_text(encoding="utf-8")
372 # Skip placeholder files that haven't been translated yet
373 if "Translation needed" in content or "> This document requires" in content:
374 continue
375
376 clean_slug = unquote(entry["slug"])
377 dest_file = dest_dir / (clean_slug + ".md")
378 if dry_run:
379 print(f" [DRY] sync-en {en_src.relative_to(repo_root)} -> {dest_file.relative_to(repo_root)}")
380 synced += 1
381 continue
382
383 # Rewrite image paths
384 content = content.replace("](/assets/images/", "](/images/")
385 content = re.sub(r'!\[([^\]]*)\]\(blob:https?://[^)]+\)', r'[formula]', content)
386 # Inject H1 title from frontmatter if body has no H1
387 fm = read_front_matter(en_src)
388 if fm:
389 title_val = fm.get("title", {})
390 title_en = title_val.get("en", "") if isinstance(title_val, dict) else str(title_val)
391 if not title_en:
392 title_en = title_val.get("zh", "") if isinstance(title_val, dict) else ""
393 if title_en:
394 fm_end_idx = content.find("---", 3)
395 if fm_end_idx >= 0:
396 body = content[fm_end_idx + 3:].lstrip("\n")
397 if not body.startswith("# "):
398 content = content[:fm_end_idx + 3] + "\n\n# " + title_en + "\n\n" + body
399 dest_file.write_text(content, encoding="utf-8")
400 synced += 1
401 return synced
402
403
404def _entry_row(entry: dict, repo_root: Path) -> str:

Callers 1

mainFunction · 0.85

Calls 2

read_front_matterFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected