From a4944b0c3a57265db22fa7696b3a33564614a0ef Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 14 Feb 2020 18:05:28 -0800 Subject: [PATCH] Added blob_prefix to support relative image urls --- gitsrht/blueprints/repo.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 7f67ddb..22bf4c4 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -93,9 +93,12 @@ def summary(owner, repo): commits = get_last_3_commits(tip) link_prefix = url_for( 'repo.tree', owner=repo.owner, repo=repo.name, - ref=default_branch.name) + ref=f"{default_branch.name}/") # Trailing slash needed + blob_prefix = url_for( + 'repo.raw_blob', owner=repo.owner, repo=repo.name, + ref=f"{default_branch.name}/", path="") # Trailing slash needed readme = get_readme(git_repo, tip, - link_prefix=link_prefix) + link_prefix=[link_prefix, blob_prefix]) tags = [(ref, git_repo.get(git_repo.references[ref].target)) for ref in git_repo.listall_references() if ref.startswith("refs/tags/")] @@ -176,10 +179,16 @@ def lookup_ref(git_repo, ref, path): @repo.route("///tree//") def tree(owner, repo, ref, path): owner, repo = get_repo_or_redir(owner, repo) + + if ref and "/" in ref: + ref, _, path = ref.partition("/") + with GitRepository(repo.path) as git_repo: if git_repo.is_empty: return render_empty_repo(owner, repo) + # lookup_ref will cycle through the path to separate + # the actual ref from the actual path commit, ref, path = lookup_ref(git_repo, ref, path) if isinstance(commit, pygit2.Tag): commit = git_repo.get(commit.target) -- 2.38.4