使用 javascript 代替 Sphinx 的默认目录树
我正在使用 sphinx 自动生成 html 页面。目录真的很长,所以我尝试向 toctree 的 div 添加一个新的 html 类(除其他外),以便我可以使用 JavaScript 库。基本上想要改变 toctree 生成 HTML 的方式。
我找到了 globaltoc.html 文件,将其放入 _templates 文件夹中,并取消注释 conf.py 中的 template_path强>。
这是 _templates 目录中的文件。
{% extends '!globaltoc.html' %}
<div class="toctree-wrapper compound dhtmlxTree" id="toc", setImagePath="_static/imgs/csh_dhx_skyblue/">
{{ toctree() }}
</div>
如果我这样做完全错误,请告诉我另一种方法。我希望能够在纯粹的休息中做到这一点,但这似乎不可能。我查看了 Sphinx 模板的有限示例,这就是我能找到的全部。
总体目标是使用 dhtmlxTree 用于非常大的树。我已将所需的 .js 文件和 .css 文件添加到 layout.html 中。我只需要包含 toctree 的 div 来获得我需要的类。我可以通过手动编辑来获得我需要的结果,现在我需要自动化它。
感谢您的帮助。
I'm using sphinx to auto-generate html pages. The Table of Contents is really long so I'm trying to add a new html class (among other things) to the toctree's div so I can use a javascript library. Basically wanting to change how the toctree generates its HTML.
I've found the globaltoc.html file, put it in the _templates folder and uncommented the template_path in conf.py.
This is the file in the _templates directory.
{% extends '!globaltoc.html' %}
<div class="toctree-wrapper compound dhtmlxTree" id="toc", setImagePath="_static/imgs/csh_dhx_skyblue/">
{{ toctree() }}
</div>
If I'm doing this completely wrong please tell me another way to do this. I'd like to be able to this in pure reST, but it doesn't seem possible. I've looked at the limited examples on Sphinx templating and this is all I can find.
The overall goal of this is to use dhtmlxTree for use with a very large tree. I've already added the required .js files and .css files to layout.html. I just need the div that contains the toctree to have the class I need. I can get the results I need by editing it manually, now i need to automate it.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信我的问题有两种可能的解决方案:
使用 Jinja 模板编写 javascript 和项目符号列表。目前,我不熟悉使用递归 Jinja 标志。因此,这个解决方案虽然可能,但可能会比第二个解决方案让我更加沮丧。
只需减少 toctree 指令的 :maxdepth: 属性即可。它被设置为 4。减少这个数字会使目录更小,因此更容易阅读。
在考虑了查看所有图层的需要之后,我意识到这很愚蠢,而且它降低了目录的实用性。所以我只是将 :maxdepth: 减少到 2,一切又回到了 reST 和 Sphinx 提供的简单性。
更好的设计每次都胜过炫酷因素。
I believe there are two possible solutions to my problem:
Using Jinja templates to write the javascript and the bulleted list. Currently, I'm not familiar with using the recursive Jinja flag. So this solution, while possible, may cause me more frustration than the second solution.
Simply reducing the :maxdepth: attribute for the toctree directive. It was set to 4. Reducing this number makes the Table of Contents smaller and therefore easier to read.
After thinking about the need to see all the layers, I realized it was just silly and it reduced the usefulness of the Table of Contents. So I just reduced the :maxdepth: to 2 and everything is back to the simplicity that reST and Sphinx offers.
Better design trumps the cool factor every time.