pydata-sphinx-theme icon indicating copy to clipboard operation
pydata-sphinx-theme copied to clipboard

Consider using a python function for our sidebar templating

Open choldgraf opened this issue 5 years ago • 1 comments

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)

choldgraf avatar Mar 03 '20 07:03 choldgraf

Is it still a wanted feature, as we have now completely dropped the "only-sidebar" layout ?

12rambau avatar Sep 06 '22 12:09 12rambau

Isn't it already the case ? https://github.com/pydata/pydata-sphinx-theme/blob/48227ce0be976e2092b74e87e463669f8c7b98ea/src/pydata_sphinx_theme/init.py#L363

12rambau avatar Oct 11 '22 06:10 12rambau

I think that's correct but I'm not sure, it has been a while since I thought about this :-)

choldgraf avatar Oct 11 '22 10:10 choldgraf

yep you did it here: https://github.com/pydata/pydata-sphinx-theme/pull/219

12rambau avatar Oct 18 '22 15:10 12rambau