Skip to content

adding an edit this page button to the TOC #65

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

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
"twitter_url": "https://twitter.com/pandas_dev",
}

html_context = {
"github_user": "pandas-dev",
"github_repo": "pandas-sphinx-theme",
"github_version": "master",
"doc_path": "docs",
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
Expand Down
18 changes: 18 additions & 0 deletions docs/user_guide/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,21 @@ at the bottom. You can hide these buttons with the following configuration:
html_theme_options: {
"show_prev_next": False
}


Add an Edit this Page button
============================

You can add a button to each page that will allow users to edit the page text
directly and submit a pull request to update the documentation. To include this
button in the right sidebar of each page, add the following configuration to
your ``conf.py`` file:

.. code:: python

html_context = {
"github_user": "<your-github-org>",
"github_repo": "<your-github-repo>",
"github_version": "<your-branch>",
"doc_path": "<path-from-root-to-your-docs>",
}
1 change: 1 addition & 0 deletions pandas_sphinx_theme/docs-toc.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% set page_toc = get_page_toc_object() %}

{% include "edit_this_page.html" %}
{%- if page_toc.children | length > 1 %}
<div class="tocsection onthispage"><i class="fas fa-list"></i> On this page</div>
{% endif -%}
Expand Down
8 changes: 8 additions & 0 deletions pandas_sphinx_theme/edit_this_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% if sourcename is defined and github_user is defined %}
{% set src = sourcename.split('.') %}
<div class="tocsection editthispage">
<a href="https://github.com/{{ github_user }}/{{ github_repo }}/edit/{{ github_version }}/{{ doc_path }}/{{ pagename }}.{{ src[-2] }}">
<i class="fas fa-pencil-alt"></i> Edit this page
</a>
</div>
{% endif %}
6 changes: 5 additions & 1 deletion pandas_sphinx_theme/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,8 @@ i.fa-twitter-square:before {

div.tocsection i {
padding-right: .5rem;
}
}

div.editthispage {
padding-bottom: .6rem;
}