Skip to content

Commit

Permalink
fix schettino72#10: dont raise error if there is no toctree
Browse files Browse the repository at this point in the history
No navlinks to toctree if there is only one toctree defined.
  • Loading branch information
schettino72 committed Apr 21, 2019
1 parent 1e6945d commit 2db1de8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Changes
- add breadcrumbs
- add page navigation on page top
- fix #12: load extensions JS files
- fix #10: don't raise error if there is no toctree
- no navlinks to toctree if there is only one toctree defined


0.2.0 (*2019-03-19*)
Expand Down
3 changes: 3 additions & 0 deletions sphinx_press_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def add_doctree_data(app, pagename, templatename, context, doctree):
title = tree['caption']
if not title:
title = app.env.titles[tree['parent']].astext()

res.append({
'docname': tree['parent'],
'anchor': '#{}'.format(tree.parent.parent['ids'][0]),
'title': title,
'current': current0,
'entries': entries,
Expand Down
18 changes: 10 additions & 8 deletions sphinx_press_theme/util/navlinks.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{# create one link per each toctree from master_doc #}
{% for tree in toctree_data %}
<div class="nav-item">
<a href="{{ pathto(tree.entries[0].name) }}"
class="nav-link {% if tree.current %} router-link-active{% endif %}">
{{tree.title}}
</a>
</div>
{% endfor %}
{% if toctree_data|length > 1 %}
{% for tree in toctree_data %}
<div class="nav-item">
<a href="{{ pathto(tree.docname) + tree.anchor }}"
class="nav-link {% if tree.current %} router-link-active{% endif %}">
{{tree.title}}
</a>
</div>
{% endfor %}
{% endif %}

2 changes: 1 addition & 1 deletion sphinx_press_theme/util/sidetoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% for toc in toctree_data %}
<div class="sidebar-group">
<p class="caption">
<span class="caption-text">{{toc.title}}</span>
<span class="caption-text"><a href="{{ pathto(toc.docname) + toc.anchor }}">{{toc.title}}</a></span>
</p>
<ul class="{% if toc.current %}current{% endif %}">
{% for entry in toc.entries %}
Expand Down

0 comments on commit 2db1de8

Please sign in to comment.