docs/update_links.md
本文档提供了如何更新现有MD文档内部链接的指南,以配合优化的页面结构。
[链接文本](../relative/path/to/file.md)
[Cyber RT概述](../../04_CyberRT/cyber_rt_introduction.md)
[快速导航](快速导航.md)
[安装指南](安装指南/安装指南.md)
从应用实践链接到核心模块:
更多信息请参考 [Cyber RT通信机制](../../04_CyberRT/communication_mechanism.md)
从工具使用链接到框架设计:
包管理概念详见 [包管理工具](../../框架设计/软件核心/包管理工具/包管理概念.md)
[旧链接文本](../02_Quick%20Start/old_path.md)
[新链接文本](../02_Quick%20Start/new_path.md)
保持相对路径不变:

保持完整URL:
[外部资源](https://apollo.baidu.com)
建议使用以下工具进行批量链接更新:
# 更新特定目录下的链接
find docs/ -name "*.md" -exec sed -i 's|docs/02_Quick%20Start/|../02_Quick%20Start/|g' {} \;
import os
import re
def update_links_in_md(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# 替换链接模式
content = re.sub(r'\]\(docs/([^)]+)\)', r'](../\1)', content)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
# 遍历所有md文件
for root, dirs, files in os.walk('docs'):
for file in files:
if file.endswith('.md'):
update_links_in_md(os.path.join(root, file))
更新后,使用以下方法验证链接:
npx markdown-link-check docs/*.md
重点检查:
/开头的绝对路径%20或直接使用空格如果链接更新出现问题,可以:
git checkout -- docs/