Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source_provider setting for edit link (#35 proposal) #36

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/sphinx_basic_ng/theme/basic-ng/components/edit-this-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
{%- set repo = sanitise_trailing_slash(theme_source_repository) -%}
{%- set branch = theme_source_branch -%}
{%- set subdirectory = sanitise_trailing_slash(theme_source_directory) -%}
{%- set provider = theme_source_provider -%}

{%- if not provider -%}
{#- Don't allow http:// URLs -#}
{%- if repo.startswith(
(
"http://github.com/",
"http://gitlab.com/",
"http://bitbucket.org/",
)
) -%}
{{ warning("Could not use `source_repository` provided. Please use https:// links in your `conf.py` file's `html_theme_options`.") }}
{#- Handle the relevant cases -#}
{%- elif repo.startswith("https://github.com/") -%}
{%- set provider = "github" -%}
{%- elif repo.startswith("https://gitlab.com/") -%}
{%- set provider = "gitlab" -%}
{%- elif repo.startswith("https://bitbucket.org/") -%}
{%- set provider = "bitbucket" -%}
{%- endif -%}
{%- endif -%}

{#- Figure out the document's source file path. -#}
{%- set relative_path = pagename + page_source_suffix -%}
Expand All @@ -13,26 +34,16 @@
{%- else -%}
{%- set document_path = subdirectory + "/" + relative_path -%}
{%- endif -%}

{#- Don't allow http:// URLs -#}
{%- if repo.startswith(
(
"http://github.com/",
"http://gitlab.com/",
"http://bitbucket.org/",
)
) -%}
{{ warning("Could not use `source_repository` provided. Please use https:// links in your `conf.py` file's `html_theme_options`.") }}
{#- Handle the relevant cases -#}
{%- elif repo.startswith("https://github.com/") -%}

{%- if provider == "github" -%}
{{ repo }}/edit/{{ branch }}/{{ document_path }}
{%- elif repo.startswith("https://gitlab.com/") -%}
{%- elif provider == "gitlab" -%}
{{ repo }}/-/edit/{{ branch }}/{{ document_path }}
{%- elif repo.startswith("https://bitbucket.org/") -%}
{%- elif provider == "bitbucket" -%}
{{ repo }}/src/{{ branch }}/{{ document_path }}?mode=edit&at={{ branch }}
{#- Fail with a warning -#}
{%- else -%}
{{ warning("Could not understand `source_repository` provided: " + repo) }}
{{ warning("`source_provider` <" + provider + "> not known and cannot be extracted from `source_repository` provided: " + repo) }}
{%- endif -%}
{%- endmacro -%}

Expand Down