Skip to content

Commit

Permalink
Fix 'Edit this page' url construction
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Feb 2, 2024
1 parent 6f52343 commit a0bc538
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,21 @@ def define_env(env):

def on_pre_page_macros(env):
"""The mkdocs-macros hook just before an inidvidual page render."""
repos: Repos = env.conf["pulp_repos"] # type: ignore

# Configure the edit_url with correct repository and path
repo = env.page.file.url.partition("/")[0]
edit_url = env.page.edit_url.replace(
"https://github.com/pulp/pulpcore/edit/master/",
f"https://github.com/pulp/{repo}/edit/master/",
).replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
src_uri = env.page.file.src_uri.replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
if src_uri != "index.md":
repo, _, path = src_uri.partition("/")
else:
repo = "pulpcore"
path = f"{SRC_DOCS_DIRNAME}/index.md"

repo_obj = repos.get(repo)
repo_branch = "main"
if repo_obj:
repo_branch = repo_obj.status.original_refs
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
env.page.edit_url = edit_url


Expand Down
4 changes: 4 additions & 0 deletions src/pulp_docs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def update_local_checkouts(self):
repo.status.original_refs = repo.branch
repo.branch = checkout_refs

def get(self, repo_name: str) -> t.Optional[Repo]:
repo = [r for r in self.all if r.name == repo_name] or [None]
return repo[0]

@property
def all(self):
return [self.core_repo] + self.content_repos + self.other_repos
Expand Down

0 comments on commit a0bc538

Please sign in to comment.