Skip to content

Commit

Permalink
Merge pull request #25 from BoboTiG/feat-source_default_branch
Browse files Browse the repository at this point in the history
feat: add `source_branch` to control the edit source link default branch
  • Loading branch information
lepture authored Feb 3, 2024
2 parents 96b8ce8 + 24b7e5a commit f1c8e8e
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
"source_docs_path": "/docs/", # Optional
}
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 f1c8e8e

Please sign in to comment.