问题描述
我正在为包含模块的平台构建文档。我想让文档存在于这些模块存储库中,并使用 include 命令将它们包含在“主”文档中。
我尝试了以下方法:
.. include:: https://github.com/12rambau/sepal_ui_template/blob/master/doc/en.rst
是否可以在include
命令中使用绝对链接?
解决方法
没有。完全限定的 URL 与文档无关。根据 include
directive 的文档:
指令参数是要包含的文件的路径,相对于包含指令的文档。
还有其他选择,包括 this one。
,我的主要目标不是使用 include
命令,而是避免代码重复并使用网络上可用的文件。根据 @Steve piercy 的回答,我想出了这个解决方案:
在conf.py文件中我从github复制文件内容
小心并使用 raw.githubusercontent.com
链接避免导入 html
# [...]
# -- Copy the modules documentation ------------------------------------------
from urllib.request import urlretrieve
urlretrieve (
"https://raw.githubusercontent.com/12rambau/sepal_ui_template/master/doc/en.rst","modules/sepal_ui_template.rst"
)
在我的文档中的 modules/sepal_ui_template.rst
下创建文件后,我可以安全地访问它。
每次我重建文档时都会重新下载。