/
kreyndelHam
/
Konstructorium
Обзор
Документация
Войти
/
kreyndelHam
/
Konstructorium
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
dev
scripts/docs/check_markdown_links.py
49 строк
1 KB
MihahamYT
Code Style + docstrings
22 апр 2026, 00:29
22 апр 2026, 00:29
eea24b4
Код
Авторство
О чём код?
"""Validate local markdown links inside the documentation tree.""" from __future__ import annotations import re from pathlib import Path ROOT = Path(__file__).resolve().parents[2] DOCS_DIR = ROOT / "docs" LINK_RE = re.compile(r"\[[^\]]+\]\(([^)]+)\)") def should_ignore(link: str) -> bool: """Return True for link targets that should not be checked as local files.""" return ( link.startswith("http://") or link.startswith("https://") or link.startswith("mailto:") or link.startswith("#") ) def main() -> int: """Run broken-link checks and return process exit code.""" errors: list[str] = [] for md_file in DOCS_DIR.rglob("*.md"): text = md_file.read_text(encoding="utf-8") for match in LINK_RE.finditer(text): raw_link = match.group(1).strip() link = raw_link.split("#", 1)[0] if not link or should_ignore(link): continue target = (md_file.parent / link).resolve() if not target.exists(): errors.append(f"{md_file.relative_to(ROOT)} -> missing: {raw_link}") if errors: print("Broken local markdown links found:") for item in errors: print(f"- {item}") return 1 print("Local markdown links check passed.") return 0 if __name__ == "__main__": raise SystemExit(main())