How to remove module and class prefix in TOC names? #692
-
I'm not sure if this is a Sphinx issue or a Furo issue, but I'll start here anyway. There are 2 things going on that I'd like help with:
I have tried setting |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
For 2, at least, I would check your (This might solve 1, too, but our docset is organized manually into pages, so auto-generated page titles based on the module name aren't used anywhere.) |
Beta Was this translation helpful? Give feedback.
-
Hi @dgw, Thank you! I was looking for hours yesterday, and setting It did not help with #1. The closest I could find was to go through each .rst file and remove the package/module parents from the title. For example, in edgeimpulse_api.api.admin_api.rst, I changed
to
That helped make some of the longer titles much easier to read on the left sidebar and on the page itself (see screenshot). My follow-up question: is there any way to change the title like this automatically (either in sphinx-apidoc or sphinx-build) without needing to manually edit every .rst file? My search has not turned up anything, and my backup plan is to create a pre-processing script that runs between sphinx-apidoc and sphinx-build that modifies the titles in all .rst files (not pretty, so I'm hoping to avoid this option). |
Beta Was this translation helpful? Give feedback.
-
Anyone coming at this from the future: using templates you're able to specify the header of each generated page. This header is then used as the toctree entry name. If you use something like this one below for your module templates, it should shorted the names without any hassle. {{ name | escape | underline}}
.. automodule:: {{ fullname }}
{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes
.. autosummary::
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}
.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}
.. autosummary::
:toctree:
:template: custom-class-template.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}
.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block modules %}
{% if modules %}
.. rubric:: Modules
.. autosummary::
:toctree:
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %} |
Beta Was this translation helpful? Give feedback.
For 2, at least, I would check your
toc_object_entries_show_parents
setting inconf.py
. With the default value ("domain"), in a Python project, I'm not seeing excessive prefixes in Furo's right sidebar.(This might solve 1, too, but our docset is organized manually into pages, so auto-generated page titles based on the module name aren't used anywhere.)