Skip to content

Commit

Permalink
feat: add source_branch to control the edit source link default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Jan 30, 2024
1 parent 069111f commit 8ae0392
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/customisation/sidebar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ configuration. Simply add the following to your Sphinx ``conf.py`` file:
"source_type": "github|gitlab|bitbucket",
"source_user": "<username>",
"source_repo": "<repository>",
"source_branch": "master", # Optional
}
With this configuration, Shibuya will automatically include an "Edit This Page" link in
Expand Down
9 changes: 6 additions & 3 deletions src/shibuya/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def create_edit_source_link(context: Dict[str, Any]):
source_user = context.get("source_user")
source_repo = context.get("source_repo")
source_docs_path = context.get("source_docs_path", "/docs/")
source_branch = context.get("source_branch", "master")
source_edit_template = context.get("source_edit_template")

def edit_source_link(filename: str) -> str:
Expand All @@ -61,11 +62,13 @@ def edit_source_link(filename: str) -> str:
return

if source_type == "github":
return f"https://github.com/{source_user}/{source_repo}/blob/master{source_docs_path}{filename}"
url = f"https://github.com/{source_user}/{source_repo}/blob"
elif source_type == "gitlab":
return f"https://gitlab.com/{source_user}/{source_repo}/-/blob/master{source_docs_path}{filename}"
url = f"https://gitlab.com/{source_user}/{source_repo}/-/blob"
elif source_type == "bitbucket":
return f"https://bitbucket.org/{source_user}/{source_repo}/src/master{source_docs_path}{filename}"
url = f"https://bitbucket.org/{source_user}/{source_repo}/src"

return f"{url}/{source_branch}{source_docs_path}{filename}"

return edit_source_link

Expand Down

0 comments on commit 8ae0392

Please sign in to comment.