首页 > 解决方案 > 仅侧边栏中的 Sphinx 目录树

问题描述

我是 Sphinx 的新手,一段时间以来一直在寻找这个问题的解决方案。

我的索引页面由 index.rst 组成,其中包含一个目录树。该页面在正文和侧边栏中显示 TOC。我只想在侧边栏上显示目录,而不是在每个页面正文中输入一些文本。特别是主要的“Welcome to My Place”,目前index.html和index.rst应该只是一段blurb而不是TOC。

我试过这个:

Welcome to My Place
==================

.. toctree::
   :hidden:
   :maxdepth: 2
   :caption: Contents:

但这会从页面和侧边栏中删除目录。我怎样才能让它工作?

编辑:这是它的显示方式,我希望 TOC 只出现在侧边栏中。 截屏

标签: python-sphinxsidebartoctree

解决方案


您可以通过包含一个单独的文件来执行此操作,并将conf.py 中toctree的变量指向该文件。master_doc


conf.py

# ...
master_doc = "contents"
# ...rest of the document

contents.rst

.. toctree::

   example

index.rst

# Landing Page
 Welcome!

推荐阅读