Files
calminer/scripts/check_docs_links.py
zwitschi 97b1c0360b
Some checks failed
Run Tests / e2e tests (push) Failing after 1m27s
Run Tests / lint tests (push) Failing after 6s
Run Tests / unit tests (push) Failing after 7s
Refactor test cases for improved readability and consistency
- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation.
- Adjusted assertions to use multi-line formatting for better readability.
- Added new test cases for theme settings API to ensure proper functionality.
- Ensured consistent use of line breaks and spacing across test files for uniformity.
2025-10-27 10:32:55 +01:00

51 lines
1.5 KiB
Python

"""Simple Markdown link checker for local docs/ files.
Checks only local file links (relative paths) and reports missing targets.
Run from the repository root using the project's Python environment.
"""
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
DOCS = ROOT / "docs"
MD_LINK_RE = re.compile(r"\[([^\]]+)\]\(([^)]+)\)")
errors = []
for md in DOCS.rglob("*.md"):
text = md.read_text(encoding="utf-8")
for m in MD_LINK_RE.finditer(text):
label, target = m.groups()
# skip URLs
if (
target.startswith("http://")
or target.startswith("https://")
or target.startswith("#")
):
continue
# strip anchors
target_path = target.split("#")[0]
# if link is to a directory index, allow
candidate = (md.parent / target_path).resolve()
if candidate.exists():
continue
# check common implicit index: target/ -> target/README.md or target/index.md
candidate_dir = md.parent / target_path
if candidate_dir.is_dir():
if (candidate_dir / "README.md").exists() or (
candidate_dir / "index.md"
).exists():
continue
errors.append((str(md.relative_to(ROOT)), target, label))
if errors:
print("Broken local links found:")
for src, tgt, label in errors:
print(f"- {src} -> {tgt} ({label})")
exit(2)
print("No broken local links detected.")