Skip to content

Commit

Permalink
Clean up the sidebar table of contents
Browse files Browse the repository at this point in the history
Now "Table of Contents" only appears once on the index page.

Apparently it is impossible to include the index page in the table of contents
and have it expand its subheadings in the globaltoc. You can use "self", but
it doesn't expand the subheadings. If you include "index" it complains about
recursive toc.

I had to do this manually by modifying the sidebar templates. The result is
not ideal (the index page is sidebar styled a little differently from the
rest), but it is better than before. I also added "self" so that the main page
appears on the global toc for every other page. This makes the main page
appear twice on itself. I don't know how to fix that.
  • Loading branch information
asmeurer committed Nov 21, 2017
1 parent ca9d965 commit c8096ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/_templates/globaltocindex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
basic/globaltoc.html
~~~~~~~~~~~~~~~~~~~~

Sphinx sidebar template: global table of contents.

:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.

Modified to work properly with the index page
#}
{{ toctree() }}
15 changes: 15 additions & 0 deletions docs/_templates/localtocindex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{#
basic/localtoc.html
~~~~~~~~~~~~~~~~~~~

Sphinx sidebar template: local table of contents.

:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.

Modified to work properly with the index page
#}
{%- if display_toc %}
<h3><a href="{{ pathto(master_doc) }}">{{ _('Table Of Contents') }}</a></h3>
{{ toc }}
{%- endif %}
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
html_sidebars = {
'**': ['globaltoc.html', 'sidebarhelp.html',
'searchbox.html'],
'index': ['localtoc.html', 'globaltoc.html', 'sidebarhelp.html',
'index': ['localtocindex.html', 'globaltocindex.html', 'sidebarhelp.html',
'searchbox.html'],
}

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Contents:
.. toctree::
:maxdepth: 2

self
commandline
recipes
api
Expand Down

0 comments on commit c8096ab

Please sign in to comment.