Skip to content

Commit

Permalink
Improve handling for raw github repo links (#8483)
Browse files Browse the repository at this point in the history
* Improve handling for raw github repo links

* Fix strict mode

(cherry picked from commit b1a5b1a)
  • Loading branch information
SchrodingersGat committed Nov 14, 2024
1 parent f23d405 commit 5e003d9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,19 @@ def sourcefile(filename, branch=None, raw=False):
if not os.path.exists(file_path):
raise FileNotFoundError(f'Source file {filename} does not exist.')

repo_url = get_repo_url(raw=raw)

if raw:
url = f'{repo_url}/{branch}/{filename}'
else:
url = f'{repo_url}/blob/{branch}/{filename}'
# Construct repo URL
repo_url = get_repo_url(raw=False)
url = f'{repo_url}/blob/{branch}/{filename}'

# Check that the URL exists before returning it
if not check_link(url):
raise FileNotFoundError(f'URL {url} does not exist.')

if raw:
# If requesting the 'raw' URL, take this into account here...
repo_url = get_repo_url(raw=True)
url = f'{repo_url}/{branch}/{filename}'

return url

@env.macro
Expand Down

0 comments on commit 5e003d9

Please sign in to comment.