pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
618 stars 321 forks source link

Disabling `use_edit_page_button` for specific files #1187

Closed pseusys closed 1 year ago

pseusys commented 1 year ago

I wonder, if it's possible to enable Edit this page and Show sources buttons on some pages - and hide them on the other?
Maybe using a kind of paths list (like in exclude_patterns) or using file metadata?

drammock commented 1 year ago

There are at least a couple ways to do this on the user end (i.e., without changing the theme at all). One is to change CSS properties of the elements to display:none on some pages, using Javascript. Another is to override the theme template and include in your override a conditional that checks against specific filenames. Here's the current template:

https://github.com/pydata/pydata-sphinx-theme/blob/e81108b6641f566c99d523804dc89bbcb8f4e3b9/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/edit-this-page.html#L1-L16

So you could copy that file, save it in the _templates folder of your docs, and add a condition to that long conditional on the first line

{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix and pagename not in my_list_of_uneditable_pages %}

Will that work for your use case?

pseusys commented 1 year ago

That would've worked, but I receive the following error:

Reason: UndefinedError("'get_edit_provider_and_url' is undefined")

This is my configuration file.

drammock commented 1 year ago

oops, that variable name just changed yesterday in #1177. This is the version before that change which should be compatible with the released version of the theme:

https://github.com/pydata/pydata-sphinx-theme/blob/30b2c526147cea17a4b3d23b5eb8b8381fc700f0/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/edit-this-page.html#L1-L8

choldgraf commented 1 year ago

If they are very specific files and not too many, you could always manually add some CSS rules on the page content itself (as raw css and html if using markdown, or with a "raw" directive if using RST)

pseusys commented 1 year ago

Thanks a lot! I would prefer using raw - not to depend on specific (and outdated) theme version!

AhmedBasem20 commented 1 year ago

Hi @drammock I'm trying to hide the edit button of the auto-generated API docs pages. I used javascript as you mentioned but the edit button is still there. Could you guide me on what's maybe gone wrong there? here is my _static/custom.js file:

var githubPath = document.querySelector("div.tocsection.editthispage a").href;
var dirNames = githubPath.split('/');
if (dirNames.includes('apidoc') == true ) {
    var tocSection = document.querySelector("div.tocsection.editthispage");
    tocSection.style.display = "none";
      }