如何使用Sphinx文档在Confluence中构建多页面并分别生成两个Python脚本的文档页面
解决方案:将两个Python脚本的文档发布到Confluence独立页面
要实现把plants.py和interpolate.py的文档分别发布到Confluence的两个独立页面,核心是调整你的Sphinx文档结构和Confluence构建配置,具体步骤如下:
1. 拆分独立的RST文档文件
当前你把两个模块的文档都写在index.rst里,这会导致它们被合并到同一个Confluence页面。我们需要把每个模块的文档拆成单独的RST文件:
- 创建
plants.rst文件,内容如下:
Plants Module Documentation ****************************** .. automodule:: plants :members:
- 创建
interpolate.rst文件,内容如下:
Interpolate Module Documentation ****************** .. automodule:: interpolate :members:
2. 更新根目录的index.rst
修改index.rst,让它通过toctree引用这两个新文件(如果不需要根页面显示额外内容,也可以简化,但保留toctree能让Sphinx正确识别文档结构):
.. spectRRa documentation master file, created by sphinx-quickstart on Fri Apr 24 11:55:57 2020. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Documentation Overview ****************************** .. toctree:: :maxdepth: 2 :caption: Modules: plants interpolate
3. 调整Confluence构建配置(conf.py)
接下来修改conf.py,确保每个RST文件对应一个独立的Confluence页面:
- 如果你不希望生成根页面(即
index.rst对应的页面),可以添加排除设置:
# 排除根页面,只发布plants和interpolate对应的页面 confluence_exclude_pages = ['index']
- (可选)如果想把这两个页面放在同一个父页面下(比如之前注释的
Plants APIs),可以取消注释并设置:
confluence_parent_page = 'Plants APIs'
- (可选)如果需要自定义Confluence页面的名称(和RST标题不同),可以添加标题覆盖配置:
confluence_title_overrides = { 'plants': 'Plants Script Documentation', 'interpolate': 'Interpolate Script Documentation' }
4. 重新构建并发布
运行Sphinx构建命令(比如sphinx-build -b confluence source build/confluence),之后你的两个模块文档就会分别发布到Confluence的两个独立页面中了。
原理说明:sphinxcontrib.confluencebuilder插件默认会将每个RST源文件转换为一个单独的Confluence页面,拆分文件是实现独立页面的核心操作。
内容的提问来源于stack exchange,提问作者Divyank
相关产品推荐
相关产品推荐

