engineering-portfolio/scripts/check_links.py
Vickenty Zherebov e6814b6437
All checks were successful
Portfolio checks / checks (pull_request) Successful in 4s
Собрать главное портфолио, резюме и каталог проектов
2026-10-20 15:13:01 +03:00

23 lines
860 B
Python

"""Check repository-relative links in Markdown without network access."""
import re
from pathlib import Path
from urllib.parse import unquote, urlsplit
root = Path(__file__).resolve().parents[1]
errors = []
checked = 0
for source in root.rglob("*.md"):
if ".git" in source.relative_to(root).parts:
continue
for target in re.findall(r"!?\[[^\]]*\]\(([^\s)]+)\)", source.read_text()):
parsed = urlsplit(target)
if parsed.scheme or parsed.netloc or not parsed.path:
continue
path = (source.parent / unquote(parsed.path)).resolve()
checked += 1
if not path.is_relative_to(root) or not path.exists():
errors.append(f"{source.relative_to(root)}: {target}")
if errors:
raise SystemExit("Broken local links:\n" + "\n".join(errors))
print(f"Local Markdown links: {checked} checked")