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

Function sync_content_to_docs

scripts/generate_docs_index.py:310–349  ·  view source on GitHub ↗

Copy data layer *.zh.md files into docs/zh/ / for VitePress rendering. Strips the .zh suffix so the route becomes /zh/ / . 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

308
309
310def sync_content_to_docs(section_key: str, entries: List[dict], repo_root: Path, dry_run: bool = False) -> int:
311 """
312 Copy data layer *.zh.md files into docs/zh/<section_key>/ for VitePress rendering.
313 Strips the .zh suffix so the route becomes /zh/<section_key>/<slug>.
314 Returns count of files synced.
315 """
316 synced = 0
317 dest_dir = repo_root / "docs" / "zh" / section_key
318 if not dry_run:
319 dest_dir.mkdir(parents=True, exist_ok=True)
320
321 for entry in entries:
322 src_file: Path = entry["file"]
323 # URL-decode slug to avoid %-encoded filenames that break VitePress/Rollup
324 clean_slug = unquote(entry["slug"])
325 dest_file = dest_dir / (clean_slug + ".md")
326 if dry_run:
327 print(f" [DRY] sync {src_file.relative_to(repo_root)} -> {dest_file.relative_to(repo_root)}")
328 synced += 1
329 continue
330 content = src_file.read_text(encoding="utf-8")
331 # Rewrite image paths: /assets/images/ -> /images/ (VitePress public dir)
332 content = content.replace("](/assets/images/", "](/images/")
333 # Remove blob: URLs (WordPress editor temp objects, not downloadable)
334 content = re.sub(r'!\[([^\]]*)\]\(blob:https?://[^)]+\)', r'[formula]', content)
335 # Inject H1 title from frontmatter if body has no H1
336 fm = read_front_matter(src_file)
337 if fm:
338 title_val = fm.get("title", {})
339 title_zh = title_val.get("zh", "") if isinstance(title_val, dict) else str(title_val)
340 if title_zh:
341 # Find end of frontmatter in content
342 fm_end_idx = content.find("---", 3)
343 if fm_end_idx >= 0:
344 body = content[fm_end_idx + 3:].lstrip("\n")
345 if not body.startswith("# "):
346 content = content[:fm_end_idx + 3] + "\n\n# " + title_zh + "\n\n" + body
347 dest_file.write_text(content, encoding="utf-8")
348 synced += 1
349 return synced
350
351
352def sync_en_content_to_docs(section_key: str, entries: List[dict], repo_root: Path, dry_run: bool = False) -> int:

Callers 1

mainFunction · 0.85

Calls 2

read_front_matterFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected