(text: str, target_path: Path, article_map: dict[str, dict[str, str]])
| 83 | |
| 84 | |
| 85 | def 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 | |
| 105 | def rel_link(from_dir: Path, to_path: Path) -> str: |
no test coverage detected