Skip to content

DOC: added button to edit on GitHub #61956

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions doc/_templates/edit-this-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{# Displays a link to the edit interface of the page source in the specified Version Control System. #}
{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix and show_edit_this_page %}
{% set src = sourcename.split('.') %}
<div class="tocsection editthispage">
<a href="{{ get_edit_provider_and_url()[1] }}">
<i class="fa-solid fa-pencil"></i>
{% set provider = get_edit_provider_and_url()[0] %}
{% block edit_this_page_text %}
{% if provider %}
{% trans provider=provider %}Edit on {{ provider }}{% endtrans %}
{% else %}
{% trans %}Edit{% endtrans %}
{% endif %}
{% endblock %}
</a>
</div>
{% endif %}
13 changes: 13 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"sphinx.ext.mathjax",
"sphinx.ext.todo",
"nbsphinx",
"show_edit_this_page",
]

exclude_patterns = [
Expand Down Expand Up @@ -270,6 +271,8 @@
"icon": "fa-brands fa-mastodon",
},
],
"secondary_sidebar_items": ["page-toc", "sourcelink", "edit-this-page"],
"use_edit_page_button": True,
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -393,6 +396,16 @@
html_context = {
"redirects": dict(moved_api_pages),
"header": header,
"github_user": "pandas-dev",
"github_repo": "pandas",
"github_version": "main",
"doc_path": "doc/source",
"exclude_edit_this_page_pagename": [
"index"
], # specific pages, e.g., index, development/index
"exclude_edit_this_page_directory": [
"api"
], # all files in a directory, e.g., development, reference
}

# If false, no module index is generated.
Expand Down
19 changes: 19 additions & 0 deletions doc/sphinxext/show_edit_this_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Sphinx extension for checking if Edit this Page button should show on this page."""


def html_page_context(app, pagename, templatename, context, doctree):
if (
any(
part in context["exclude_edit_this_page_directory"]
for part in pagename.split("/")
)
or pagename in context["exclude_edit_this_page_pagename"]
):
context["show_edit_this_page"] = False
else:
context["show_edit_this_page"] = True


def setup(app):
app.connect("html-page-context", html_page_context)
return {"parallel_read_safe": True}