Skip to content

Commit

Permalink
fix: ignore hash based links (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain authored Dec 12, 2024
1 parent cc3ff1c commit e60bb19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def internal_to_external_urls(internal_url: str) -> str:
And [this is a correct relative link]({WORKING_INTERNAL_URL}).
And [this is an incorrect relative link]({BROKEN_INTERNAL_URL}).
This [hash link](#hash-link) should be ignored.
![Broken Image]({BROKEN_IMG_URL})
"""

Expand Down
8 changes: 8 additions & 0 deletions wiki/wiki/report/wiki_broken_links/wiki_broken_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def get_broken_links(
broken_links = []
for el in links:
url = el.attrs.get("href") or el.attrs.get("src")

if is_hash_link(url):
continue

is_relative = is_relative_url(url)
relative_url = None

Expand All @@ -108,6 +112,10 @@ def is_relative_url(url: str) -> bool:
return url.startswith("/")


def is_hash_link(url: str) -> bool:
return url.startswith("#")


def is_broken_link(url: str) -> bool:
try:
status_code = get_request_status_code(url)
Expand Down

0 comments on commit e60bb19

Please sign in to comment.