Prefix README links to rendered pages

Relative links from project summaries resulted in raw pages rather
than rendered pages for both mercurial and git repositories.

This patch is intended to match the behavior of git.sr.ht and hg.sr.ht
README rendering by passing the previous raw links as secondary link
prefixes (for rendering images) but otherwise link to rendered
resources.

related ticket: todo.sr.ht/~sircmpwn/hub.sr.ht/67
This commit is contained in:
Nolan Prescott 2020-12-08 02:12:32 -05:00 committed by Drew DeVault
parent 5c97b72d51
commit 64cd1e0443
1 changed files with 6 additions and 4 deletions

View File

@ -120,8 +120,9 @@ class GitService(SrhtService):
content = repo["md"] or repo["markdown"]
if content:
link_prefix = repo_url + "/blob/HEAD/"
html = markdown(content["object"]["text"], link_prefix=link_prefix)
blob_prefix = repo_url + "/blob/HEAD/"
rendered_prefix = repo_url + "/tree/HEAD/"
html = markdown(content["object"]["text"], link_prefix=[rendered_prefix, blob_prefix])
return Markup(html)
content = repo["plaintext"]
@ -271,7 +272,8 @@ class HgService(SrhtService):
override = try_html_readme(self.session, _hgsrht, user, repo_name)
if override is not None:
return override
link_prefix = repo_url + "/raw/"
blob_prefix = repo_url + "/raw/"
rendered_prefix = repo_url + "/browse/"
for readme_name in readme_names:
r = self.session.get(f"{_hgsrht}/api/repos/{repo_name}/raw/{readme_name}",
headers=encrypt_request_authorization(user))
@ -279,7 +281,7 @@ class HgService(SrhtService):
continue
elif r.status_code != 200:
raise Exception(r.text)
return format_readme(r.text, readme_name, link_prefix)
return format_readme(r.text, readme_name, link_prefix=[rendered_prefix, blob_prefix])
return format_readme("")
def create_repo(self, user, valid, visibility):