MCPcopy Create free account
hub / github.com/crisxuan/bestJavaer / fix_links

Function fix_links

scripts/generate_english_main_docs.py:85–102  ·  view source on GitHub ↗
(text: str, target_path: Path, article_map: dict[str, dict[str, str]])

Source from the content-addressed store, hash-verified

83
84
85def fix_links(text: str, target_path: Path, article_map: dict[str, dict[str, str]]) -> str:
86 target_dir = target_path.parent
87
88 replacements = {
89 "../README.md": rel_link(target_dir, ROOT / "README.md"),
90 "./openspec-superpowers-gstack-project-onboarding.md": "./openspec-superpowers-gstack-project-onboarding.md",
91 }
92
93 for source_rel, mapped in article_map.items():
94 source_abs = ROOT / source_rel
95 english_abs = ROOT / mapped["english_path"]
96 replacements[rel_link(target_dir, source_abs)] = rel_link(target_dir, english_abs)
97 replacements["../" + source_rel] = rel_link(target_dir, english_abs)
98 replacements["./" + source_rel] = rel_link(target_dir, english_abs)
99
100 for old, new in sorted(replacements.items(), key=lambda item: len(item[0]), reverse=True):
101 text = text.replace(f"]({old})", f"]({new})")
102 return text
103
104
105def rel_link(from_dir: Path, to_path: Path) -> str:

Callers 1

translate_docFunction · 0.85

Calls 1

rel_linkFunction · 0.85

Tested by

no test coverage detected