"git@code.it4i.cz:moldyn/lib4neuro.git" did not exist on "4fcb51b48ae969df2d8eff6f52f64c9a069bdfc1"
Newer
Older
#!/bin/python3
import re
import requests
from pathlib import Path
def check_links_in_mdx(directory):
mdx_files = Path(directory).rglob("*.mdx")
url_pattern = re.compile(r'\[.*?\]\((http[s]?://.*?)\)')
for mdx_file in mdx_files:
with open(mdx_file, "r", encoding="utf-8") as f:
content = f.read()
links = url_pattern.findall(content)
for link in links:
try:
response = requests.head(link, allow_redirects=True, timeout=5)
if response.status_code >= 400:
print(f"Broken link in {mdx_file}: {link} (Status: {response.status_code})")
except requests.RequestException:
print(f"Error checking {link} in {mdx_file}")
check_links_in_mdx("content/docs")