Skip to content

Disabling use_edit_page_button for specific files #1187

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

Closed
pseusys opened this issue Feb 15, 2023 · 6 comments
Closed

Disabling use_edit_page_button for specific files #1187

pseusys opened this issue Feb 15, 2023 · 6 comments

Comments

@pseusys
Copy link

pseusys commented Feb 15, 2023

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
Copy link
Collaborator

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:

{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix %}
{% 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 %}

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
Copy link
Author

pseusys commented Feb 15, 2023

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
Copy link
Collaborator

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:

{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix %}
{% set src = sourcename.split('.') %}
<div class="tocsection editthispage">
<a href="{{ get_edit_url() }}">
<i class="fa-solid fa-pencil"></i> {{ _("Edit this page") }}
</a>
</div>
{% endif %}

@choldgraf
Copy link
Collaborator

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
Copy link
Author

pseusys commented Feb 16, 2023

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

@AhmedBasem20
Copy link

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";
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants