【问题标题】:How can I link the generated index page in ReadTheDocs navigation bar?如何在 ReadTheDocs 导航栏中链接生成的索引页面?
【发布时间】:2017-03-26 04:22:45
【问题描述】:

我在 ReadTheDocs 上使用 Sphinx 创建我的文档,使用他们的主题。构建过程会生成一个 genindex.html 文件,可以通过以下方式引用:

Link to the :ref:`genindex` page.

创建:

链接到Index 页面。

我无法将genindex 添加到我的目录树中,例如:

.. toctree:

   foo
   bar
   genindex

因为它是一个自动生成的文件,在渲染时不存在。此外,Sphinx 期望 genindex 是一个名为 genindex.rst 的本地文件。

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

【问题讨论】:

  • 解决方法:创建一个标题为“索引”的genindex.rst 文件,并在index.rst(顶级)的目录树中引用它。创建的genindex.html 将被生成的索引替换,所以最后链接指向正确的文件。
  • 这能回答你的问题吗? How can i include the `genindex` in a Sphinx TOC?
  • @AkibAzmain 请查看答案日期,您会发现我的答案之前存在 :)
  • 你能解释一下方程式吗:4 years, 2 months > 4 years, 9 months@Paebbles?
  • @AkibAzmain 这个问题的答案是 13.11.2016,你链接的答案是 18.02.2017。这不是关于何时提出问题,而是关于何时回答问题。你的评论问:Does this answer your question?。如果您问:以前有人问过吗,那么是的,以前有人问过,而我 4 年前没看到。

标签: indexing python-sphinx restructuredtext read-the-docs toctree


【解决方案1】:

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


Sphinx 在构建根目录中将索引创建为denindex.html。它不能在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

源文件genindex.rst:

.. This file is a placeholder and will be replaced

Index
#####

导航栏截图:

【讨论】:

  • Index 在主页上正确显示,但在打开章节时消失。
  • 哦,我使用的是自动构建,直到我触摸它们页面才刷新。
猜你喜欢
  • 2018-02-18
  • 1970-01-01
  • 2015-07-14
  • 2020-12-28
  • 2016-10-24
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 2023-02-06
相关资源
最近更新 更多