使用自我创建一个网站地图,在sphinx中的toctree看起来坏了? [英] Using self to create a sitemap with toctree in sphinx seem broken?

查看:381
本文介绍了使用自我创建一个网站地图,在sphinx中的toctree看起来坏了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新一个相当大的项目的常见问题,我想在页面顶部添加一个问题的索引,所以用户更容易找到他们要查找的内容。



Sphinx文档 toctree article 指出特殊条目名称self表示包含toctree指令的文档,如果要从toctree生成sitemap,这很有用。这就是我想要的。问题是自己看起来很坏,只包括当前的文件标题而不是字幕。当我在另一个文档中引用常见问题时,它正常工作,只有在文档本身才会失败。



演示

  .. toctree :: 
:maxdepth:3

faq
pre>

在其他文件结果中




  • 常见问题


    • 常见问题


      • 问题1

      • 问题2

      • 问题3


    • 不明显的行为等需要知道




Inside faq

  .. toctree :: 
:maxdepth:3

self

结果




  • 常见问题



我以为可能是因为狮身人面像在转换toctree并且尝试将toctree移动到页面底部时不知道字幕。没有变化。



任何关于如何使用sphinx在页面本身中包含页面索引的想法将不胜感激

解决方案

您正在寻找的是内容指令。



在页面标题之后插入以下块以构建问题列表:

  ..内容:: 
:本地:
:深度:1

它会产生:




  • 问题1

  • 问题2

  • 问题3


I'm updating a FAQ for a fairly big project and I would like to add an index of the questions at the top of the page, so it becomes easier for users to find what they're looking for.

The Sphinx documentation toctree article states "The special entry name self stands for the document containing the toctree directive. This is useful if you want to generate a "sitemap" from the toctree." This is what I want. The problem is that self seem broken and only includes the current documents title and not the subtitles. It works correctly when I'm in another document and references the FAQ, only in the document itself does it fail.

To demonstrate

.. toctree::
   :maxdepth: 3

   faq

In other file results in

  • Frequently Asked Questions
    • FAQ
      • Question 1
      • Question 2
      • Question 3
    • Non-obvious behaviour and other need to know

Inside faq

.. toctree::
   :maxdepth: 3

   self

results in

  • Frequently Asked Questions

I've thought that maybe it was because sphinx wasn't aware of the subtitles when the toctree is converted and tried moving the toctree to the bottom of the page. No change.

Any ideas on how to include a index of a page in the page itself with sphinx would be greatly appreciated

解决方案

What your are looking for is the contents directive.

Insert the following block after the title of your page to build the list of questions :

.. contents::
   :local:
   :depth: 1

It will produce:

  • Question 1
  • Question 2
  • Question 3

这篇关于使用自我创建一个网站地图,在sphinx中的toctree看起来坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆