| 1 |
import os |
| 2 |
import re |
| 3 |
from urllib.parse import urlparse |
| 4 |
|
| 5 |
os.chdir("content/_guides") |
| 6 |
|
| 7 |
links = r"\[(.+?)\]\((.+?)\)" |
| 8 |
|
| 9 |
files = os.listdir(".") |
| 10 |
valid_links = [link.removesuffix(".md").replace("_", "-") for link in files] |
| 11 |
|
| 12 |
has_invalid = False |
| 13 |
|
| 14 |
for file in files: |
| 15 |
with open(file) as f: |
| 16 |
doc = f.read() |
| 17 |
|
| 18 |
if not doc: |
| 19 |
continue |
| 20 |
|
| 21 |
matches = re.findall(links, doc) |
| 22 |
|
| 23 |
for match in matches: |
| 24 |
link = match[1] |
| 25 |
|
| 26 |
url = urlparse(link) |
| 27 |
if url.scheme: |
| 28 |
continue |
| 29 |
|
| 30 |
if link.startswith("/static"): |
| 31 |
continue |
| 32 |
|
| 33 |
link = link.split("#")[0] |
| 34 |
|
| 35 |
if link not in valid_links: |
| 36 |
print(f"Invalid link: {link} in file: {file}") |
| 37 |
has_invalid = True |
| 38 |
|
| 39 |
if has_invalid: |
| 40 |
exit(1) |