pydata-sphinx-theme
pydata-sphinx-theme copied to clipboard
Consider using a python function for our sidebar templating
I find the sidebar templating logic to be a bit confusing to wrap my head around. I wonder if it could be made a little bit more modular if we generated that HTML with a Python function. E.g., I feel like we must be able to generate that structure with a recursive function, similar to how we parse the nav items on the page.
Maybe this would be easier than having a bunch of if/then statements in the Jinja itself? I tried making a little demo function, and if we pass it nav like so:
{{ my_func(nav) }}
then nav has this structure:
[{'active': False,
'children': [],
'title': 'User Guide',
'url': '../user_guide/index.html'},
{'active': False,
'children': [],
'title': 'Contributing',
'url': '../contributing.html'},
{'active': True,
'children': [{'active': False,
'children': [],
'title': 'Structural Elements',
'url': 'structure.html'},
{'active': False,
'children': [],
'title': 'Paragraph Level Markup',
'url': 'demo.html'},
... and so on
So it might be easy to loop through that and recursively generate the right HTML. Do you think this is worth a shot? Or am I over-thinking this?
(one reason I'm interested in this is to make it easier to switch back-and-forth between "sidebar + topbar" and "only sidebar" layouts)
Is it still a wanted feature, as we have now completely dropped the "only-sidebar" layout ?
Isn't it already the case ? https://github.com/pydata/pydata-sphinx-theme/blob/48227ce0be976e2092b74e87e463669f8c7b98ea/src/pydata_sphinx_theme/init.py#L363
I think that's correct but I'm not sure, it has been a while since I thought about this :-)
yep you did it here: https://github.com/pydata/pydata-sphinx-theme/pull/219