Pae*_*els 7 indexing restructuredtext python-sphinx read-the-docs toctree
我正在使用他们的主题在 ReadTheDocs 上使用 Sphinx 创建我的文档。构建过程会生成一个 genindex.html 文件,可以通过以下方式引用:
Link to the :ref:`genindex` page.
Run Code Online (Sandbox Code Playgroud)
这创造了:
链接到索引页面。
我无法添加genindex到我的 toctree,例如像这样:
.. toctree:
foo
bar
genindex
Run Code Online (Sandbox Code Playgroud)
因为它是一个自动生成的文件,在渲染时不存在。此外,Sphinx 期望 genindex 是一个名为genindex.rst.
如何将其添加到我的 ToC/导航中?
至于没有人发布更好的解决方案,我会写下我的解决方法作为一个有效的解决方案。
Sphinxdenindex.html在构建根目录中创建索引为 a 。它不能在toctree指令中引用,因为该指令引用了 ReST 文件。那么如何解决呢?
因此,让我们创建一个genindex.rst文件并从toctree指令中引用它。这也会genindex.html在构建根目录中创建一个。所有链接都按预期创建。该genindex.html文件需要定义一个类似于“Index”的标题,用作导航栏中的链接标题。
从 ReST 文件写入所有 HTML 文件后,Sphinx 生成其索引并覆盖genindex.html.
源文件:
源文件index.rst:
.. toctree::
:caption: Introduction
chapter1
chapter2
.. toctree::
:caption: Main Documentation
chapter3
chapter4
.. toctree::
:caption: Appendix
genindex
Run Code Online (Sandbox Code Playgroud)
源文件genindex.rst:
.. This file is a placeholder and will be replaced
Index
#####
Run Code Online (Sandbox Code Playgroud)
导航栏截图: