Add Tags to sidebar, and hack in a maxdepth to avoid redundant links

This commit is contained in:
Jordan Cook 2023-07-11 15:27:41 -05:00
parent 1cd5598692
commit 58ea59d67f
3 changed files with 38 additions and 6 deletions

View File

@ -42,8 +42,8 @@ copybutton_prompt_is_regexp = True
tags_create_tags = True
tags_extension = ['md']
tags_output_dir = 'tags'
tags_overview_title = 'Tags'
tags_page_title = 'Tags'
tags_overview_title = '{fas}`tags` Tags'
tags_page_title = '{fas}`tag` Tag'
tags_create_badges = True
tags_badge_colors = {
'python': 'primary',
@ -114,3 +114,38 @@ html_theme_options = {
# bg3 #665c54
# bg4 #7c6f64
# gray #928374
SIDEBAR_MAXDEPTH = 2
def setup(app):
"""Run some additional steps after the Sphinx builder is initialized"""
app.connect('builder-inited', patch_furo_sidebar_toctree)
def patch_furo_sidebar_toctree(app):
"""Monkey-patch Furo's sidebar toctree to override its max depth. This is done to include the
tags overview page generated by sphinx-tags without adding redundant items to the tree.
Otherwise, a page shows up once in the main tree, and then an additional time under every tag
it's associated with.
Furo made the (sensible) design choice to always display the entire site in the sidebar tree,
and doesn't provide a way to limit the tree depth. Reference:
https://github.com/pradyunsg/furo/pull/128
Note: This involves private utility methods, and is likely to break in future versions of Furo.
"""
import furo
from furo import _compute_navigation_tree
def mod_compute_navigation_tree(context):
toctree = context["toctree"]
def mod_toctree(maxdepth=-1, **kwargs):
return toctree(maxdepth=SIDEBAR_MAXDEPTH, **kwargs)
context["toctree"] = mod_toctree
return _compute_navigation_tree(context)
furo._compute_navigation_tree = mod_compute_navigation_tree

View File

@ -20,5 +20,6 @@ open_source
succulents
photography
about_site
tags/tagsindex
asdf
```

View File

@ -89,10 +89,6 @@
</div>
</div>
<div align="center">
<a href="tags/tagsindex.html"><i class="fa-solid fa-tags"></i>Tags</a>
</div>
<div align="right">
{%- if last_updated -%}
<div class="last-updated">Last updated on {{ last_updated }}</div>