SPB Git

Repository Public MIT

check-docs.py 1.6 KB 31 lines python

1#!/usr/bin/env python32# ORIX Calc3# File: Scripts/check-docs.py4# Description: Verifies that every relative link and image in the Markdown documentation points to a file that exists,5#              and that every Mermaid block is fenced correctly. Exits non-zero on a broken reference.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9import os, re, subprocess, sys1011root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))12files = subprocess.check_output(["git", "ls-files", "-co", "--exclude-standard", "*.md"], cwd=root, text=True).split("\n")13broken, checked, mermaid, external = [], 0, 0, set()14for rel in filter(None, files):15    path = os.path.join(root, rel)16    if not os.path.exists(path) or "/.build/" in rel: continue17    text = open(path, encoding="utf-8").read()18    mermaid += len(re.findall(r"^```mermaid", text, flags=re.M))19    if len(re.findall(r"^```", text, flags=re.M)) % 2: broken.append((rel, "unbalanced code fence"))20    prose = re.sub(r"```.*?```", "", text, flags=re.S)21    targets = re.findall(r"\]\(([^)\s]+)\)", prose) + re.findall(r'(?:src|href)="([^"]+)"', prose)22    for t in targets:23        if t.startswith(("http://", "https://", "mailto:")): external.add(t); continue24        if t.startswith("#"): continue25        target = t.split("#")[0]26        checked += 127        if not os.path.exists(os.path.normpath(os.path.join(os.path.dirname(path), target))): broken.append((rel, t))28print(f"{checked} relative links and images checked in {len(files) - 1} Markdown files; {mermaid} Mermaid diagrams; {len(external)} distinct external URLs")29for rel, t in broken: print(f"BROKEN  {rel}: {t}")30sys.exit(1 if broken else 0)31
Files main
Menu

Theme