diff --git a/doc/_templates/edit-this-page.html b/doc/_templates/edit-this-page.html new file mode 100644 index 0000000000000..0c9d9345623d3 --- /dev/null +++ b/doc/_templates/edit-this-page.html @@ -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('.') %} +
+ + + {% 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 %} + +
+{% endif %} diff --git a/doc/source/conf.py b/doc/source/conf.py index f222a228531ff..11b6d5c789196 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -69,6 +69,7 @@ "sphinx.ext.mathjax", "sphinx.ext.todo", "nbsphinx", + "show_edit_this_page", ] exclude_patterns = [ @@ -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. @@ -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. diff --git a/doc/sphinxext/show_edit_this_page.py b/doc/sphinxext/show_edit_this_page.py new file mode 100644 index 0000000000000..5d1df06ab8ff7 --- /dev/null +++ b/doc/sphinxext/show_edit_this_page.py @@ -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}