{%- 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) -%} {#- 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) }} {%- 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 %} {{ _("View this page") }} {% endblock link_available %} {%- else -%} {% block link_not_available %}{% endblock %} {%- endif -%} {%- endif -%}