如何在Sphinx文档中添加自定义页脚?(reStructuredText的)

cwd*_*cwd 22 unix linux restructuredtext makefile python-sphinx

如果我有一些文档,例如Galleria的文档,我该如何设置它以便在运行make html命令时它会在每个页面上添加一个自定义页脚?

我看到如果我将它输出为pdf格式,我可能会使用conf.py 的latex前言部分.

谢谢!

Unc*_*eiv 30

您必须通过提供如下的html文件来扩展默认布局:

{% extends '!layout.html' %}

{% block footer %}
        <!-- your html code here -->
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

将其保存在_templates/子目录中,layout.html并确保告诉conf.py在哪里找到此目录:

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Run Code Online (Sandbox Code Playgroud)

有关模板的更多信息,请访问:http://sphinx.pocoo.org/templating.html

  • 如果有人想知道,`_templates`目录的默认位置(基于`conf.py`中的`templates_path`设置)与`conf.py`所在的目录相同,这应该是你的来源`目录.此外,如果您希望您的页脚具有与默认页脚相同的样式,则需要在`<div class ="footer">`标记中包围页脚的HTML. (5认同)
  • 对于RTD主题:`{%extends'!footer.html'%} {%block extrafooter%} <! - 您的HTML代码 - > {%endblock%} (4认同)
  • 您还可以在sphinx安装目录中找到要覆盖的layout.html文件.然后你可以复制出{%block%}部分并按照UncleZeiv的说明覆盖它,只改变你想要改变的部分.我的文件位于<pythondir>\Lib\site-packages\Sphinx-1.1.3-py2.7.egg\sphinx\themes\<theameame>\layout.html (2认同)