Skip to content

Commit

Permalink
Add (back?) support for RtD context inference on top of page buttons
Browse files Browse the repository at this point in the history
This was removed since the RtD folks reached out about this
configuration injection being due for deprecation. However, the
alternatives don't seem to be fully fleshed out just yet so leave this
in while we figure out the next steps.
  • Loading branch information
pradyunsg committed May 6, 2024
1 parent 1b4cf89 commit ec8815a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
29 changes: 25 additions & 4 deletions docs/customisation/top-of-page-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,37 @@ The `{filename}` component will be replaced with the full path to the file, as k
Furo does not enforce that the `source_edit_link` / `source_view_link` contain `{filename}` or any sort of correctness check on these URLs. Make sure to manually confirm that the link works.
```

## Linking to copied sources

If [`html_show_sourcelink`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_show_sourcelink) and [`html_copy_source`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_copy_source) are `True` (which are the defaults), and the documentation does not configure any of the above variables, the view button will link to the raw sources copied in by Sphinx.

## Read the Docs support

```{versionchanged} 2024.05.06
This feature has been tentatively removed (but the removal has not been released), as a better approach is investigated. See [this discussion](https://github.com/pradyunsg/furo/discussions/785) for more details.
```{note}
This feature is only available for projects hosted on GitHub.
```

If you're building documentation on Read the Docs using a gh.neting.cc-hosted repository as the source, the edit button is enabled by default.
Furo has built-in support for inferring details from Read the Docs' environment for GitHub projects and enabling these buttons.

For such projects, Furo will try to automatically infer the source repository, branch, and directory from the Read the Docs build environment unless the above configuration variable are set.

### Edit button on Read the Docs

The _edit_ button will link to GitHub's edit view for the document.

### View button on Read the Docs

The _view_ button will link to the raw sources copied in by Sphinx, if available, [as noted above](#linking-to-copied-sources). If raw sources are not copied, it will link to GitHub's plain view for the document.

If you do not want to link to copied sources, you can set the following in the `conf.py`:

```python
html_copy_source = False
html_show_sourcelink = False
```

### Disabling on Read the Docs

If you wish to disable this, use {ref}`top_of_page_button` and set it to `None`.
If you wish to disable these default buttons, use {ref}`top_of_page_buttons` and set it to `[]`.

[sphinx-html_theme_options]: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_theme_options
8 changes: 8 additions & 0 deletions src/furo/theme/furo/components/edit-this-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
{% block link_available -%}
{{ furo_edit_button(determine_page_edit_link()) }}
{%- endblock %}

{% block link_not_available %}
{# Make nice things happen, on Read the Docs #}
{%- if READTHEDOCS and conf_py_path and page_source_suffix and github_user != "None" and github_repo != "None" and github_version and pagename and page_source_suffix %}
{% set url = "https://github.com/" + github_user + "/" + github_repo + "/edit/" + github_version + conf_py_path + pagename + page_source_suffix %}
{{ furo_edit_button(url) }}
{%- endif -%}
{% endblock %}
8 changes: 8 additions & 0 deletions src/furo/theme/furo/components/view-this-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
{% block link_available -%}
{{ furo_view_button(determine_page_view_link()) }}
{%- endblock %}

{% block link_not_available %}
{# Make nice things happen, on Read the Docs #}
{%- if READTHEDOCS and conf_py_path and page_source_suffix and github_user != "None" and github_repo != "None" and github_version and pagename and page_source_suffix %}
{% set url = "https://github.com/" + github_user + "/" + github_repo + "/blob/" + github_version + conf_py_path + pagename + page_source_suffix + "?plain=true" %}
{{ furo_view_button(url) }}
{%- endif -%}
{% endblock %}

0 comments on commit ec8815a

Please sign in to comment.