Sphinx 配置如何在标题中设置“面包屑”?我有一个 Sphinx 项目,我看到的只是项目名称;如果我跳转到子页面,我会迷路并且看不到当前页面的路径。

野外的一些例子:

https://docs.python.org/2.7/library/argparse.html

参见第一行:文档 >> Python 标准库 >> 15. 通用操作系统服务

http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

查看顶部的圆角矩形

scipy 的源代码似乎在这里:


看起来 Sphinx“基本”主题具有作为“relbar”内置的此功能:

来自 https://github.com/sphinx-doc/sphinx/blob/master/sphinx/themes/basic/layout.html :

{%- macro relbar() %} 
    <div class="related" role="navigation" aria-label="related navigation"> 
      <h3>{{ _('Navigation') }}</h3> 
      <ul> 
        {%- for rellink in rellinks %} 
        <li class="right" {% if loop.first %}style="margin-right: 10px"{% endif %}> 
          <a href="{{ pathto(rellink[0]) }}" title="{{ rellink[1]|striptags|e }}" 
             {{ accesskey(rellink[2]) }}>{{ rellink[3] }}</a> 
          {%- if not loop.first %}{{ reldelim2 }}{% endif %}</li> 
        {%- endfor %} 
        {%- block rootrellink %} 
        <li class="nav-item nav-item-0"><a href="{{ pathto(master_doc) }}">{{ shorttitle|e }}</a>{{ reldelim1 }}</li> 
        {%- endblock %} 
        {%- for parent in parents %} 
          <li class="nav-item nav-item-{{ loop.index }}"><a href="{{ parent.link|e }}" {% if loop.last %}{{ accesskey("U") }}{% endif %}>{{ parent.title }}</a>{{ reldelim1 }}</li> 
        {%- endfor %} 
        {%- block relbaritems %} {% endblock %} 
      </ul> 
    </div> 
{%- endmacro %} 

另见 http://www.sphinx-doc.org/en/stable/templating.html

但我不知道如何启用。


好吧,我真的很困惑。我得到了一些东西,但不是我想要的方式。

我有我的项目“MyDoc”的 index.rst:

Top Level Page Title Is Here 
============================ 
 
content goes here 
 
.. toctree:: 
   :maxdepth: 2 
 
   introduction 
   (other files) 

然后我有introduction.rst

Introduction 
============ 
 
content goes here 
 
.. toctree:: 
   :maxdepth: 2 
 
   test1 

和test1.rst

Test1 
============ 
 
blah blah 
  • 对于 index.html,它在 relbar 中显示 MyDoc。
  • 对于 introduction.html,它在 relbar 中显示 MyDoc。 (我会期望 MyDoc >> 简介)
  • 对于 test1.html,它在 relbar 中显示 MyDoc >> Introduction。 (我本来希望 MyDoc >> 介绍 >> Test1)

我想我感到困惑的是为什么它会这样工作。

请您参考如下方法:

我不确定您在问什么问题,因为您似乎至少更改过一次。然而,从您后来的一些评论来看,您似乎希望当前文档名称显示为面包屑链接中的最后一项。

碰巧我只是想自己做。我最终将此添加到我的 layout.html:

{# Show the current document in the navigation bar. #} 
{% block relbaritems %} 
<li class="nav-item">{{ title|striptags|e }}</li> 
{% endblock %} 

...这似乎对我很有效。我没有把它设为链接,因为指向当前文档的链接似乎是不必要的,但如果您想要它,通过查看基础 layout.html< 应该不难弄清楚如何去做。/.

但是,我没有弄清楚如何为根文档隐藏它。如果有人知道怎么做,请跟进!


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!