Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,17 @@ def get_file_ids(path):
continue

parsed = urlparse(link)
is_absolute_internal = False
if parsed.scheme and parsed.scheme in ("http", "https"):
if not link.startswith(SITE_URL):
site_url_no_slash = SITE_URL.rstrip("/")
if not link.startswith(SITE_URL) and not link.startswith(site_url_no_slash):
continue # External link
# Internal absolute URL (e.g. https://ucp.dev/foo) -> /foo
link = link[len(SITE_URL) - 1 :] # Keep the leading slash
is_absolute_internal = True
if link.startswith(SITE_URL):
link = link[len(SITE_URL) - 1 :]
else:
link = "/" + link[len(site_url_no_slash) :]
parsed = urlparse(link)

path_part = parsed.path
anchor_part = parsed.fragment
Expand All @@ -179,7 +185,7 @@ def get_file_ids(path):

# Resolve Target File
if not path_part:
target_file = file_path
target_file = ROOT_DIR / "index.html" if is_absolute_internal else file_path
elif path_part.startswith("/"):
# Absolute path from root
rel_path = path_part[1:]
Expand Down
Loading