-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_missing.py
More file actions
16 lines (16 loc) · 839 Bytes
/
Copy pathcheck_missing.py
File metadata and controls
16 lines (16 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os, re, urllib.parse
md_image_regex = re.compile(r'!\[([^\]]*)\]\(([^)]+)\)')
for root, _, files in os.walk("hugo-src/content"):
for f in files:
if f.endswith(".md"):
path = os.path.join(root, f)
with open(path, "r", encoding="utf-8") as file:
for match in md_image_regex.finditer(file.read()):
src = urllib.parse.unquote(match.group(2).split(' ')[0])
if src.startswith("http") or src.startswith("data:"): continue
if src.startswith("/"):
expected = os.path.join("hugo-src/static", src.lstrip("/"))
else:
expected = os.path.join(root, src)
if not os.path.exists(expected):
print(f"Missing: {src} in {path}")