Skip to content

Commit 0e9d991

Browse files
committed
feat: added show_edit_this_page ext which decides to show the button or not based on the config
1 parent 0156b09 commit 0e9d991

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

doc/_templates/edit-this-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{# Displays a link to the edit interface of the page source in the specified Version Control System. #}
2-
{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix and pagename not in exclude_edit_page_button %}
2+
{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix and show_edit_this_page %}
33
{% set src = sourcename.split('.') %}
44
<div class="tocsection editthispage">
55
<a href="{{ get_edit_provider_and_url()[1] }}">

doc/source/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"sphinx.ext.mathjax",
7070
"sphinx.ext.todo",
7171
"nbsphinx",
72+
"show_edit_this_page",
7273
]
7374

7475
exclude_patterns = [
@@ -399,7 +400,12 @@
399400
"github_repo": "pandas",
400401
"github_version": "main",
401402
"doc_path": "doc/source",
402-
"exclude_edit_page_button": ["index"],
403+
"exclude_edit_this_page_pagename": [
404+
"index"
405+
], # specific pages, e.g., index, development/index
406+
"exclude_edit_this_page_directory": [
407+
"api"
408+
], # all files in a directory, e.g., development, reference
403409
}
404410

405411
# If false, no module index is generated.

doc/sphinxext/show_edit_this_page.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Sphinx extension for checking if Edit this Page button should show on this page."""
2+
3+
def html_page_context(app, pagename, templatename, context, doctree):
4+
if (
5+
any(part in context['exclude_edit_this_page_directory'] for part in pagename.split("/")) or
6+
pagename in context['exclude_edit_this_page_pagename']
7+
):
8+
context['show_edit_this_page'] = False
9+
else:
10+
context['show_edit_this_page'] = True
11+
12+
13+
def setup(app):
14+
app.connect('html-page-context', html_page_context)
15+
return {"parallel_read_safe": True}

0 commit comments

Comments
 (0)