Skip to content

Commit a0bc538

Browse files
committed
Fix 'Edit this page' url construction
1 parent 6f52343 commit a0bc538

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/pulp_docs/mkdocs_macros.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,21 @@ def define_env(env):
238238

239239
def on_pre_page_macros(env):
240240
"""The mkdocs-macros hook just before an inidvidual page render."""
241+
repos: Repos = env.conf["pulp_repos"] # type: ignore
242+
241243
# Configure the edit_url with correct repository and path
242-
repo = env.page.file.url.partition("/")[0]
243-
edit_url = env.page.edit_url.replace(
244-
"https://github.com/pulp/pulpcore/edit/master/",
245-
f"https://github.com/pulp/{repo}/edit/master/",
246-
).replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
244+
src_uri = env.page.file.src_uri.replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
245+
if src_uri != "index.md":
246+
repo, _, path = src_uri.partition("/")
247+
else:
248+
repo = "pulpcore"
249+
path = f"{SRC_DOCS_DIRNAME}/index.md"
250+
251+
repo_obj = repos.get(repo)
252+
repo_branch = "main"
253+
if repo_obj:
254+
repo_branch = repo_obj.status.original_refs
255+
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
247256
env.page.edit_url = edit_url
248257

249258

src/pulp_docs/repository.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def update_local_checkouts(self):
209209
repo.status.original_refs = repo.branch
210210
repo.branch = checkout_refs
211211

212+
def get(self, repo_name: str) -> t.Optional[Repo]:
213+
repo = [r for r in self.all if r.name == repo_name] or [None]
214+
return repo[0]
215+
212216
@property
213217
def all(self):
214218
return [self.core_repo] + self.content_repos + self.other_repos

0 commit comments

Comments
 (0)