URL 中的狮身人面像替换

Sphinx substitution in URL

我有两个项目 A 和 B,项目 A 的文档正在为不同的版本托管,因此文档网址的格式为

http://example.org/A/1.0.0/+d/index.html
http://example.org/A/1.0.1/+d/index.html
http://example.org/A/1.2.3/+d/index.html

项目 B 依赖于 A 的特定版本。在 B 的文档中,我想将 link 留给 A 的文档,如下所示:

"See also A's documentation (v 1.0.1)"

是否可以将版本变量传递给 URL?我尝试使用 rst_prolog:

conf.py:

rst_prolog = '''
.. |a-ver| replace:: {ver}
'''.format(
    ver=meta.__a_dep_version__,
)

index.rst:

A's version: |a-ver| # this produces the correct output
See also `framework docs <http://example.com/A/|a-ver|/index.html>`_.

但在构建文档后得到 URL https://example.com/A/%7Ca-ver%7C/+d/index.html

您可以为此使用 sphinx.ext.extlinks 扩展程序。

示例

狮身人面像配置

extlinks = {'docs': ('http://example.org/A/%s/+d/index.html', 'framework docs ')}

您的文档

:docs:`1.0.1`
.. Result -> framework docs 1.0.1

:docs:`documentation (1.2.3) <1.2.3>`
.. Result -> documentation (1.2.3)