【问题标题】:How do Sphinx configurations setup "breadcrumbs"?Sphinx 配置如何设置“面包屑”?
【发布时间】:2016-12-12 08:51:38
【问题描述】:

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)

然后我有介绍.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)

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

【问题讨论】:

标签: python-sphinx breadcrumbs


【解决方案1】:

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

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

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

...这对我来说似乎很有效。我没有将其设为链接,因为指向当前文档的链接似乎是不必要的,但如果您想要这样做,通过查看基础layout.html 应该不难弄清楚如何做到这一点。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多