Sphinx文档自定义页脚¶
我在撰写「Cloud Atlas」时候,希望在每个页面下增加一段留言讨论和捐赠的链接,所以在很久以前就采用本文方法定制footer。最近又增加了 Sphinx文档评论系统 功能,也是在本文footer基础上修改,所以整理记录:
修订文档项目的
conf.py
指定模版目录:
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
在源代码项目下创建
_templates
目录,然后在该目录下创建foot.html
,增加以下内容:
{% extends '!footer.html' %}
{% block extrafooter %}
<!-- your html code here -->
<br>
<p><a href="https://github.com/huataihuang/cloud-atlas/issues">留言和讨论</a>|<a href="https://github.com/huataihuang/cloud-atlas/blob/master/source/donate.rst">请我喝一杯咖啡 👈</a></p>
<br>
<p>网站采用 <a href="https://utteranc.es/">utterances</a> 评论系统,所有评论存储在<a href="https://github.com/huataihuang/cloud-atlas/issues">GitHub issues</a> 中,如果你看不到下方的评论框,那么可能需要<a href="https://cloud-atlas.readthedocs.io/zh-cn/latest/linux/security/vpn/index.html">自备梯子</a> 👈</p>
<div class="articleComments">
{% include "comments.html" %}
</div>
{% endblock %}
然后就可以在上述 footer.html
内容部分填写自己希望在每个页面展示的内容,内容会显示在页脚上
注意:参考 How can I add a custom footer to Sphinx documentation? 提到的采用
RTD theme
:{% extends '!footer.html' %} {% block extrafooter %} <!-- your html code here --> {% endblock %}
上文
footer.html
部分内容是 Sphinx文档评论系统 ,用于我的网站和网友交流评论