Skip to content
Open
Changes from 2 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
20 changes: 17 additions & 3 deletions scripts/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,24 @@ def get_file_ids(path):

parsed = urlparse(link)
if parsed.scheme and parsed.scheme in ("http", "https"):
if not link.startswith(SITE_URL):
parsed_site = urlparse(SITE_URL)
if parsed.hostname == parsed_site.hostname:
path = parsed.path if parsed.path else "/"
site_path = parsed_site.path
site_path_no_slash = site_path.rstrip("/")
if (path == site_path_no_slash) or path.startswith(site_path):
if path.startswith(site_path):
rel_link_path = "/" + path[len(site_path) :]
else:
rel_link_path = "/"
query_part = f"?{parsed.query}" if parsed.query else ""
fragment_part = f"#{parsed.fragment}" if parsed.fragment else ""
link = rel_link_path + query_part + fragment_part
parsed = urlparse(link)
else:
continue # External link
else:
continue # External link
# Internal absolute URL (e.g. https://ucp.dev/foo) -> /foo
link = link[len(SITE_URL) - 1 :] # Keep the leading slash

path_part = parsed.path
anchor_part = parsed.fragment
Expand Down
Loading