更改 sphinx-build 主文件

Change sphinx-build master file

我可以告诉 sphinx-build 停止寻找 index.rst.

$ echo 'test' > readme.rst
$ sphinx-build -C . ./build readme.rst

这会抱怨缺少索引文件

master file /.../index.rst not found

不过我们可以解决这个问题

$ ln -s readme.rst index.rst
$ sphinx-build -C . ./build readme.rst

这实际上会构建 index.rstreadme.rst 并且它会抱怨 readme.rst 没有包含在任何目录树中。这可以通过使用 mv 而不是 ln 来解决。但是,我不想移动文件只是为了满足 sphinx-build 拥有索引文件的奇怪需求。我也不想到处挥之不去link。

我可以更改主文件的位置吗?类似的东西(不起作用):

$ sphinx-build -C -D 'master_file=readme.rst' . ./build

或者我可以告诉它一起跳过索引文件吗?例如(不起作用):

$ sphinx-build -C -D 'exclude_patterns=index.rst' . ./build readme.rst

或者有其他方法可以解决这个问题吗?

怎么样:

sphinx-build -C . ./build readme.rst -D master_doc='readme'    

更详细:

$ ls
readme.rst
$ sphinx-build -C . ./build readme.rst -D master_doc='readme'
Running Sphinx v1.8.5
making output directory...
building [mo]: targets for 0 po files that are specified
building [html]: 1 source files given on command line
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] readme                                                          
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] readme                                                           
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded.

The HTML pages are in build.
$ ls
build       readme.rst

对于 Sphinx 3.0.2,同样的事情对我有用。

首先将您的 index.rst 重命名为 readme.rst

然后您可以在 conf.py 中指定 master_doc configuration option 并构建文档,或者在构建文档时在命令行中覆盖 conf.py 中的值。

指定于conf.py

$ sphinx-build . ./build

仅在命令行指定

$ sphinx-build . ./build -D master_doc='master'