在此处提到的 sphinx 文档页面上添加“编辑源”按钮的过程在公共 GitLab 存储库上运行良好。
html_context = {
"display_gitlab": True, # Integrate Gitlab
"gitlab_user": "MyUserName", # Username
"gitlab_repo": "MyDoc", # Repo name
"gitlab_version": "master", # Version
"conf_py_path": "/source/", # Path in the checkout to the docs root
}
但是,如何让它适用于自托管的 Gitlab 实例?
gitlab_host
中使用键
html_context
,其中该键的值是 Gitlab 的 URL,不带
https://
,例如
html_context = {
"display_gitlab": True, # Integrate Gitlab
"gitlab_host": "git.mycompany.com:1234"
"gitlab_user": "MyUserName", # Username
"gitlab_repo": "MyDoc", # Repo name
"gitlab_version": "master", # Version
"conf_py_path": "/source/", # Path in the checkout to the docs root
}
这可以用作:
{% if display_gitlab %}
<a href="https://{{ gitlab_host|default("gitlab.com") }}/
{{ gitlab_user }}/{{ gitlab_repo }}/blob/{{ gitlab_version }}
{{ conf_py_path }}{{ pagename }}{{ suffix }}" class="fa fa-gitlab">
Edit on GitLab</a>
{% endif %}