首页 > 解决方案 > 狮身人面像 index.rst 里面的目录

问题描述

Sphinx 构建的主文档的路径可以在conf.py. 但是,此目录路径反映在生成的 HTML 中,例如在 Read The Docs 中显示为缺失的索引。我想使用这种替代路径来干净地构建我的项目 - 在顶层进行配置和内部文档src,但让构建基本上摆脱它。

所以这就是我以前的:

docs
    conf.py
    index.rst
    things
        doc1.rst
        doc2.rst

这可行,但是当将大量文件添加到顶层时,Sphinx 的 makefile 等会变得混乱。我想改用这个:

docs
    conf.py
    src
        index.rst
        things
            doc1.rst
            doc2.rst

哪个构建,但index.htmlbuild/html/src而不是build/html. master_doc令我惊讶的是,除了inconf.py控制主文件的位置和名称这一事实之外,没有关于此的任何信息。我怎样才能让我的文档被构建到build/html

标签: pythonpython-sphinx

解决方案


有一个选项用于指定配置文件的位置:-c.

# conf.py
master_doc = 'index'

# structure
docs
    conf.py
    src
        index.rst
        ...

然后运行sphinx-build -b html -c . src build/html。但是,此解决方案确实需要控制 build 命令,而 Read The Docs 中没有该命令。并且似乎-c在 Sphinx 自己的 makefile 中也不起作用(使用-M而不是-b)。


推荐阅读