File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -238,12 +238,21 @@ def define_env(env):
238
238
239
239
def on_pre_page_macros (env ):
240
240
"""The mkdocs-macros hook just before an inidvidual page render."""
241
+ repos : Repos = env .conf ["pulp_repos" ] # type: ignore
242
+
241
243
# 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 } "
247
256
env .page .edit_url = edit_url
248
257
249
258
Original file line number Diff line number Diff line change @@ -209,6 +209,10 @@ def update_local_checkouts(self):
209
209
repo .status .original_refs = repo .branch
210
210
repo .branch = checkout_refs
211
211
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
+
212
216
@property
213
217
def all (self ):
214
218
return [self .core_repo ] + self .content_repos + self .other_repos
You can’t perform that action at this time.
0 commit comments