| 1 |
============== |
| 2 |
Source Buttons |
| 3 |
============== |
| 4 |
|
| 5 |
Source buttons are links to the source of your page's content (either on your site, or on hosting sites like GitHub). |
| 6 |
|
| 7 |
Add an edit button |
| 8 |
================== |
| 9 |
|
| 10 |
You can add a button to each page that will allow users to edit the page text |
| 11 |
directly and submit a pull request to update the documentation. To include this |
| 12 |
button in the secondary sidebar of each page, add the following configuration to |
| 13 |
your ``conf.py`` file in 'html_theme_options': |
| 14 |
|
| 15 |
.. code:: python |
| 16 |
|
| 17 |
html_theme_options = { |
| 18 |
"use_edit_page_button": True, |
| 19 |
} |
| 20 |
|
| 21 |
A number of providers are available for building *Edit this Page* links, including |
| 22 |
GitHub, GitLab, and Bitbucket. For each, the default public instance URL can be |
| 23 |
replaced with a self-hosted instance. |
| 24 |
|
| 25 |
|
| 26 |
GitHub |
| 27 |
------ |
| 28 |
|
| 29 |
.. code:: python |
| 30 |
|
| 31 |
html_context = { |
| 32 |
# "github_url": "https://github.com", # or your GitHub Enterprise site |
| 33 |
"github_user": "<your-github-org>", |
| 34 |
"github_repo": "<your-github-repo>", |
| 35 |
"github_version": "<your-branch>", |
| 36 |
"doc_path": "<path-from-root-to-your-docs>", |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
GitLab |
| 41 |
------ |
| 42 |
|
| 43 |
.. code:: python |
| 44 |
|
| 45 |
html_context = { |
| 46 |
# "gitlab_url": "https://gitlab.com", # or your self-hosted GitLab |
| 47 |
"gitlab_user": "<your-gitlab-org>", |
| 48 |
"gitlab_repo": "<your-gitlab-repo>", |
| 49 |
"gitlab_version": "<your-branch>", |
| 50 |
"doc_path": "<path-from-root-to-your-docs>", |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
Bitbucket |
| 55 |
--------- |
| 56 |
|
| 57 |
.. code:: python |
| 58 |
|
| 59 |
html_context = { |
| 60 |
# "bitbucket_url": "https://bitbucket.org", # or your self-hosted Bitbucket |
| 61 |
"bitbucket_user": "<your-bitbucket-org>", |
| 62 |
"bitbucket_repo": "<your-bitbucket-repo>", |
| 63 |
"bitbucket_version": "<your-branch>", |
| 64 |
"doc_path": "<path-from-root-to-your-docs>", |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
Custom Edit URL |
| 69 |
--------------- |
| 70 |
|
| 71 |
For a fully-customized *Edit this Page* URL, provide ``edit_page_url_template``, |
| 72 |
a jinja2 template string which must contain ``{{ file_name }}``, and may reference |
| 73 |
any other context values. |
| 74 |
|
| 75 |
.. code:: python |
| 76 |
|
| 77 |
html_context = { |
| 78 |
"edit_page_url_template": "{{ my_vcs_site }}{{ file_name }}{{ some_other_arg }}", |
| 79 |
"my_vcs_site": "https://example.com", |
| 80 |
"some_other_arg": "?some-other-arg" |
| 81 |
} |
| 82 |
|
| 83 |
With the predefined providers, the link text reads "Edit on GitHub/GitLab/Bitbucket". |
| 84 |
By default, a simple "Edit" is used if you use a custom URL. However, you can set |
| 85 |
a provider name like this: |
| 86 |
|
| 87 |
.. code:: python |
| 88 |
|
| 89 |
html_context = { |
| 90 |
"edit_page_url_template": "...", |
| 91 |
"edit_page_provider_name": "Provider", |
| 92 |
} |
| 93 |
|
| 94 |
This will turn the link into "Edit on Provider". |
| 95 |
|
| 96 |
|
| 97 |
Custom link text |
| 98 |
---------------- |
| 99 |
|
| 100 |
You can change the default text by extending the ``edit-this-page.html`` |
| 101 |
template. For example, if you have ``templates_path = ["_templates"]`` |
| 102 |
in your Sphinx configuration, you could put this code in |
| 103 |
`_templates/edit-this-page.html`: |
| 104 |
|
| 105 |
.. code:: html+jinja |
| 106 |
|
| 107 |
{% extends "!components/edit-this-page.html" %} |
| 108 |
|
| 109 |
{% block edit_this_page_text %} |
| 110 |
Edit this page |
| 111 |
{% endblock %} |
| 112 |
|
| 113 |
|
| 114 |
View Source link |
| 115 |
================ |
| 116 |
|
| 117 |
By default, this theme adds a button link to view the source of a page (i.e., the underlying ``reStructuredText`` or ``MyST Markdown`` for the page). |
| 118 |
To disable it, use the following configuration: |
| 119 |
|
| 120 |
|
| 121 |
.. code-block:: python |
| 122 |
|
| 123 |
html_show_sourcelink = False |