2016-11-11 97 views
2

我在ReadTheDocs上用Sphinx创建我的文档,使用他们的主题。构建过程产生genindex.html文件,它可以与被引用:如何链接ReadTheDocs导航栏中生成的索引页?

Link to the :ref:`genindex` page. 

它创建:

链接到Index页面。

我不能添加genindex我toctree,例如像这样:

.. toctree: 

    foo 
    bar 
    genindex 

,因为它是一个自动生成的文件,该文件根本不存在的渲染。此外,Sphinx预计genindex是一个名为genindex.rst的lokal文件。

如何将它添加到我的ToC /导航?

+2

解决方法:用标题 “索引” 创建'genindex.rst'文件,并在'index.rst'(顶级)toctree引用它。创建的'genindex.html'将被生成的索引替换,因此链接指向正确的文件。 – Paebbels

回答

1

至于没有人发布更好的解决方案,我会写下我的解决方法作为一个工作解决方案。


斯芬克斯创建索引作为在构建根目录中的denindex.html。它不能在toctree指令中引用,因为此指令引用了ReST文件。那么如何解决它?

因此,让我们创建一个genindex.rst文件并从toctree指令中引用它。这也会在构建根目录中创建genindex.html。所有链接都按预期创建。 genindex.html文件需要定义像“索引”这样的标题,该标题在导航栏中用作链接标题。

在从ReST文件中写入所有HTML文件后,Sphinx生成其索引并覆盖genindex.html

源文件:

源文件index.rst

.. toctree:: 
    :caption: Introduction 

    chapter1 
    chapter2 

.. toctree:: 
    :caption: Main Documentation 

    chapter3 
    chapter4 

.. toctree:: 
    :caption: Appendix 

    genindex 

源文件genindex.rst

.. This file is a placeholder and will be replaced 

Index 
##### 

导航栏截图:

enter image description here