sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.39k stars 2.09k forks source link

Help with removing "Edit on Github" option with ReadTheDocs theme #2386

Closed brianjking closed 8 years ago

brianjking commented 8 years ago

Hello,

When using http://readthedocs.org with the ReadTheDocs theme is it possible to remove the following elements? If so, how? I couldn't find anything in the documentation about this, if I overlooked it, please point me in the right direction.

Thanks!

shimizukawa commented 8 years ago

Sorry, I donkt know how to disable it because the feature is provided by readthedocs building system. So, please contact to https://github.com/rtfd/readthedocs.org or https://github.com/snide/sphinx_rtd_theme.

xcriptus commented 8 years ago

Hi, you should try to put the following line in your conf.py file

html_show_sourcelink = False

I've no revision ### after the copyright. If you want to remove the revision in the title bar you can do

html_theme_options = {
    'display_version': False}

You can also have some fun with creating a _templates directory, look at the layout.html and create a file called _templates/layout.html with your modification. This is not too complex if you have some developement skills. Have a look at the "template" section of sphinx or jinja. For instance the following file add hello world in the side bar, and then "index" in the menu

{% extends "!layout.html" %}
{% block sidebartitle %}
    HELLO WORLD
    {{ super() }}

{% endblock %}
{% block menu %}
    {{ super() }}
    <li class="toctree-l1"><a class="reference internal" href="{{ pathto('genindex') }}">Index</a></li>
    <li class="toctree-l1"><a class="reference internal" href="{{ pathto('py-modindex') }}">Modules index</a></li>
{% endblock %}

Hope this helps. Jean-marie

brianjking commented 8 years ago

@escribis

I had already tried html_show_sourcelink = False and it does remove the view page source message when using make html locally on my machine. However, it doesn't do anything about the Edit on Github display when using readthedocs.org.

The suggestion of using the details below works great when using Sphinx only, but once again, not on readthedocs.org.

html_theme_options = { 'display_version': False}

readthedocs github suggested the _templates tweaks you've noted above, however, I don't have the experience necessary and am feeling lost.

Thanks for your help thus far, anything else you can do would be greatly appreciated.

Thanks & Cheers!

brianjking commented 8 years ago

@escribis This is the template I'm using, are you saying I'd copy the source of it, remove the "edit on github" option, which I'm not even sure where it is based on a quick read of it, add this to my local repo and push for RTD to re-build it?

https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html

Thanks!

(If I had to guess the line I'd remove it would be this https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html#L147)

brianjking commented 8 years ago

@escribis actually, found it in breadcrumbs.html, but using display_github with False doesn't seem to make it work, so please try and explain what all I would need to modify in breadcrumbs.html to get this working.

Thank you so much!

https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/breadcrumbs.html#L16-L19

JimiC commented 8 years ago

I found myself in your situation where I wanted to remove certain elements from the page. I ended up doing them via javascript. You know if you include

def setup(app):
    app.add_stylesheet('css/style.css?v=1')
    app.add_javascript('js/script.css?v=1')

in conf.py and have the corresponding folders under _static, you can style your pages and execute js on them.

brianjking commented 8 years ago

Okay, I figured out the "Edit on Github" portion a while ago and thought I'd share my fixes here for anyone else looking to accomplish this.

I've also documented this on my StackOverflow question.

Assuming you're using the ReadTheDocs default theme this should work just fine.

html_context = {
"display_github": False, # Add 'Edit on Github' link instead of 'View page source'
"last_updated": True,
"commit": False,
}

References

benjaoming commented 6 years ago

This doesn't work right now because setting html_context in conf.py is broken. See: https://github.com/sphinx-doc/sphinx/issues/2442

MarSoft commented 5 years ago

Just for record, the right way is now documented here: https://docs.readthedocs.io/en/stable/guides/remove-edit-buttons.html

And if you want to only hide these links on some pages (e.g. on pages generated by autosummary which don't have corresponding github file anyway) then you can use that technique in combination with file-level metadata:

In breadcrumbs.html:

{%- extends "sphinx_rtd_theme/breadcrumbs.html" %}

{% block breadcrumbs_aside %}
{% if not meta or meta.get('github_url') != 'hide' %}
{{ super() }}
{% endif %}
{% endblock %}

On the page which should not have github link, add to the very beginning:

:github_url: hide