【问题标题】:How can I add a custom footer to Sphinx documentation? (reStructuredText)如何向 Sphinx 文档添加自定义页脚? (重构文本)
【发布时间】:2011-07-31 21:53:03
【问题描述】:

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

我发现如果我将其输出为 pdf 格式,我可能会使用 conf.py 的 the latex preamble 部分。

谢谢!

【问题讨论】:

    标签: linux unix makefile restructuredtext python-sphinx


    【解决方案1】:

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

    {% extends '!layout.html' %}
    
    {% block footer %}
            <!-- your html code here -->
    {% endblock %}
    

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

    # Add any paths that contain templates here, relative to this directory.
    templates_path = ['_templates']
    

    更多关于模板的信息可以在这里找到:https://www.sphinx-doc.org/en/master/templating.html

    【讨论】:

    • 您还可以在 sphinx 安装目录中找到您要覆盖的 layout.html 文件。然后,您可以复制 {% block %} 部分并按照 UncleZeiv 的说明覆盖它,只更改您想要更改的位。我的文件位于 \Lib\site-packages\Sphinx-1.1.3-py2.7.egg\sphinx\themes\\layout.html
    • 如果有人想知道,_templates 目录的默认位置(基于conf.py 中的templates_path 设置)与conf.py 所在的目录相同,应该成为您的source 目录。此外,如果您希望您的页脚具有与默认页脚相同的样式,则需要将页脚的 HTML 包含在 &lt;div class="footer"&gt; 标记中。
    • 有没有办法在生成的 PDF 中更改页脚?我在那里得到“内容”,虽然这个解决方案适用于 html,但也很高兴知道 PDF 版本!
    • > 如果您覆盖一个块,请在某处调用 {{ super() }} 以在扩展模板中呈现该块的内容——除非您不希望该内容显示:docs
    • 对于 RTD 主题:{% extends '!footer.html' %} {% block extrafooter %} &lt;!-- your html code here --&gt; {% endblock %}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    相关资源
    最近更新 更多