-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from pradyunsg/add-overrides-for-edit-and-view…
…-links Improve edit and view links, with overrides and `html_show_sourcelink` support
- Loading branch information
Showing
4 changed files
with
140 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 46 additions & 37 deletions
83
src/sphinx_basic_ng/theme/basic-ng/components/edit-this-page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,59 @@ | ||
{%- macro sanitise_trailing_slash(s) -%}{{ s.rstrip("/") }}{%- endmacro -%} | ||
|
||
{%- macro determine_page_edit_link() -%} | ||
{#- First, sanitise the trailing slashes. -#} | ||
{%- set repo = sanitise_trailing_slash(theme_source_repository) -%} | ||
{%- set branch = theme_source_branch -%} | ||
{%- set subdirectory = sanitise_trailing_slash(theme_source_directory) -%} | ||
|
||
{#- Figure out the document's source file path. -#} | ||
{%- set relative_path = pagename + page_source_suffix -%} | ||
{%- if not subdirectory -%} | ||
{%- set document_path = relative_path -%} | ||
{%- if theme_source_edit_link -%} | ||
{{ theme_source_edit_link.format(filename=pagename+page_source_suffix) }} | ||
{%- else -%} | ||
{%- set document_path = subdirectory + "/" + relative_path -%} | ||
{%- endif -%} | ||
{#- First, sanitise the trailing slashes. -#} | ||
{%- set repo = sanitise_trailing_slash(theme_source_repository) -%} | ||
{%- set branch = theme_source_branch -%} | ||
{%- set subdirectory = sanitise_trailing_slash(theme_source_directory) -%} | ||
|
||
{#- 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/") -%} | ||
{{ repo }}/edit/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://gitlab.com/") -%} | ||
{{ repo }}/-/edit/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://bitbucket.org/") -%} | ||
{{ repo }}/src/{{ branch }}/{{ document_path }}?mode=edit&at={{ branch }} | ||
{#- Fail with a warning -#} | ||
{%- else -%} | ||
{{ warning("Could not understand `source_repository` provided: " + repo) }} | ||
{#- Figure out the document's source file path. -#} | ||
{%- set relative_path = pagename + page_source_suffix -%} | ||
{%- if not subdirectory -%} | ||
{%- set document_path = relative_path -%} | ||
{%- 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/") -%} | ||
{{ repo }}/edit/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://gitlab.com/") -%} | ||
{{ repo }}/-/edit/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://bitbucket.org/") -%} | ||
{{ repo }}/src/{{ branch }}/{{ document_path }}?mode=edit&at={{ branch }} | ||
{#- Fail with a warning -#} | ||
{%- else -%} | ||
{{ warning( | ||
"Could not understand `source_repository` provided: " + repo + "\n" + | ||
"You should set `source_edit_link`, so that the edit link is presented." | ||
) }} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
|
||
{%- if page_source_suffix -%} | ||
{%- if theme_source_repository -%} | ||
{%- if not theme_source_branch -%} | ||
{{ warning("Provided `source_repository` but not `source_branch`. ")}} | ||
{%- endif -%} | ||
{% block link_available %} | ||
{%- set can_find_edit_link = ( | ||
(theme_source_edit_link and pagename) | ||
or (theme_source_repository and theme_source_branch) | ||
) -%} | ||
{%- if can_find_edit_link -%} | ||
{%- block link_available -%} | ||
<a href="{{ determine_page_edit_link() }}">{{ _("Edit this page") }}</a> | ||
{% endblock link_available %} | ||
{%- endblock link_available -%} | ||
{%- else -%} | ||
{% block link_not_available %}{% endblock %} | ||
{%- block link_not_available -%}{%- endblock -%} | ||
{%- endif -%} | ||
{%- endif -%} |
89 changes: 51 additions & 38 deletions
89
src/sphinx_basic_ng/theme/basic-ng/components/view-this-page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,63 @@ | ||
{%- macro sanitise_trailing_slash(s) -%}{{ s.rstrip("/") }}{%- endmacro -%} | ||
|
||
{%- macro determine_page_view_link() -%} | ||
{#- First, sanitise the trailing slashes. -#} | ||
{%- set repo = sanitise_trailing_slash(theme_source_repository) -%} | ||
{%- set branch = theme_source_branch -%} | ||
{%- set subdirectory = sanitise_trailing_slash(theme_source_directory) -%} | ||
{%- if theme_source_view_link -%} | ||
{{ theme_source_view_link.format(filename=pagename+page_source_suffix) }} | ||
{%- elif theme_source_repository -%} | ||
{#- First, sanitise the trailing slashes. -#} | ||
{%- set repo = sanitise_trailing_slash(theme_source_repository) -%} | ||
{%- set branch = theme_source_branch -%} | ||
{%- set subdirectory = sanitise_trailing_slash(theme_source_directory) -%} | ||
|
||
{#- Figure out the document's source file path. -#} | ||
{%- set relative_path = pagename + page_source_suffix -%} | ||
{%- if not subdirectory -%} | ||
{%- set document_path = relative_path -%} | ||
{%- else -%} | ||
{%- set document_path = subdirectory + "/" + relative_path -%} | ||
{%- endif -%} | ||
{#- Figure out the document's source file path. -#} | ||
{%- set relative_path = pagename + page_source_suffix -%} | ||
{%- if not subdirectory -%} | ||
{%- set document_path = relative_path -%} | ||
{%- 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/") -%} | ||
{{ repo }}/blob/{{ branch }}/{{ document_path }}?plain=true | ||
{%- elif repo.startswith("https://gitlab.com/") -%} | ||
{{ repo }}/blob/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://bitbucket.org/") -%} | ||
{{ repo }}/src/{{ branch }}/{{ document_path }} | ||
{#- Fail with a warning -#} | ||
{%- else -%} | ||
{{ warning("Could not understand `source_repository` provided: " + repo) }} | ||
{#- 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/") -%} | ||
{{ repo }}/blob/{{ branch }}/{{ document_path }}?plain=true | ||
{%- elif repo.startswith("https://gitlab.com/") -%} | ||
{{ repo }}/blob/{{ branch }}/{{ document_path }} | ||
{%- elif repo.startswith("https://bitbucket.org/") -%} | ||
{{ repo }}/src/{{ branch }}/{{ document_path }} | ||
{#- Fail with a warning -#} | ||
{%- else -%} | ||
{{ warning( | ||
"Could not understand `source_repository` provided: " + repo + "\n" + | ||
"You should set `source_view_link`, so that the view link is presented." | ||
) }} | ||
{%- endif -%} | ||
{%- elif show_source and has_source -%} | ||
{{ pathto('_sources/' + sourcename, true) }} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
|
||
{%- if page_source_suffix -%} | ||
{%- if theme_source_repository -%} | ||
{%- if not theme_source_branch -%} | ||
{{ warning("Provided `source_repository` but not `source_branch`. ")}} | ||
{%- endif -%} | ||
{% block link_available %} | ||
<a href="{{ determine_page_view_link() }}">{{ _("View this page") }}</a> | ||
{% endblock link_available %} | ||
{%- set can_find_view_link = ( | ||
(theme_source_view_link and pagename) | ||
or (show_source and has_source and sourcename) | ||
or (theme_source_repository and theme_source_branch) | ||
) -%} | ||
{%- if can_find_view_link -%} | ||
{%- block link_available -%} | ||
<a href="{{ determine_page_view_link() }}">{{ _("View sources") }}</a> | ||
{%- endblock link_available -%} | ||
{%- else -%} | ||
{% block link_not_available %}{% endblock %} | ||
{%- block link_not_available -%}{%- endblock -%} | ||
{%- endif -%} | ||
{%- endif -%} |