Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/keil-path-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
python-version: '3.11'
- run: python scripts/check_keil_paths.py
- run: python scripts/check_hex_snapshot.py
- run: python scripts/check_docs_links.py
6 changes: 3 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ feat(sensor): 添加MPU6050陀螺仪支持
### 技术文档
- [开发文档](DEVELOPMENT.md)
- [硬件文档](HARDWARE.md)
- [API参考](docs/API.md)
- [开发说明](DEVELOPMENT.md)

### 工具和环境
- [Keil uVision5](https://www.keil.com/)
Expand All @@ -272,7 +272,7 @@ feat(sensor): 添加MPU6050陀螺仪支持

## 许可证

通过向此项目贡献代码,您同意您的贡献将在 [MIT License](LICENSE) 下进行许可。
通过向此项目贡献代码,您同意您的贡献将在 [MIT License](../LICENSE) 下进行许可。

## 联系方式

Expand All @@ -283,7 +283,7 @@ feat(sensor): 添加MPU6050陀螺仪支持

## 相关文档

- [README.md](README.md) - 项目概述
- [README.md](../README.md) - 项目概述
- [DEVELOPMENT.md](DEVELOPMENT.md) - 开发文档
- [HARDWARE.md](HARDWARE.md) - 硬件说明

Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ printf("Temperature: %.1f°C\r\n", temperature);

## 相关文档

- [README.md](README.md) - 项目概述
- [README.md](../README.md) - 项目概述
- [HARDWARE.md](HARDWARE.md) - 硬件详细说明
- [CONTRIBUTING.md](CONTRIBUTING.md) - 贡献指南

Expand Down
2 changes: 1 addition & 1 deletion docs/HARDWARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ PC13 -> Buzzer

## 相关文档

- [README.md](README.md) - 项目概述
- [README.md](../README.md) - 项目概述
- [DEVELOPMENT.md](DEVELOPMENT.md) - 开发文档
- [CONTRIBUTING.md](CONTRIBUTING.md) - 贡献指南

Expand Down
49 changes: 49 additions & 0 deletions scripts/check_docs_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Validate repository-local links in Markdown documentation.

External destinations and fragment-only links are intentionally excluded;
this checker verifies local filesystem destinations, not external URLs.
"""
from pathlib import Path
import re
from urllib.parse import unquote, urlsplit

ROOT = Path(__file__).resolve().parents[1]
LINK = re.compile(r"!?(?:\[[^\]\n]*\])\(([^)\n]+)\)")


def check_links():
problems = []
inspected = 0
for md in sorted(ROOT.rglob("*.md")):
for match in LINK.finditer(md.read_text(encoding="utf-8")):
target = match.group(1).strip()
if target.startswith("<") and ">" in target:
target = target[1:target.index(">")]
else:
target = target.split(maxsplit=1)[0]
if not target or target.startswith("#"):
continue
parsed = urlsplit(target)
if parsed.scheme or parsed.netloc:
continue
clean = unquote(parsed.path)
if not clean:
continue
inspected += 1
destination = (ROOT / clean.lstrip("/")) if clean.startswith("/") else (md.parent / clean)
destination = destination.resolve()
try:
destination.relative_to(ROOT)
except ValueError:
problems.append("{}: local link escapes repository: {}".format(md.relative_to(ROOT), target))
continue
if not destination.exists():
problems.append("{}: missing local target: {}".format(md.relative_to(ROOT), target))
print("Checked {} local Markdown links".format(inspected))
if problems:
raise SystemExit("\n".join(problems))
print("All checked local links resolve.")


if __name__ == "__main__":
check_links()
Loading