als*_*052 2 html css themes python-sphinx
我在向 Sphinx .html 文件添加自定义页脚时遇到一些问题。我正在使用sphinx_rtd_theme。我已经检查了这篇文章并尝试了它(以及评论中的一些建议)但无济于事。我不确定我错过了什么。如果我没有在这里发布足够的内容来实际指出导致问题的原因,我深表歉意。任何帮助或建议表示赞赏!
我的 css 主题文件已被我自己(很差地)修改过(我不是 HTML/CSS 人员!),但我认为这并不重要?我唯一能想到的另一件事是,当我重新编译输出文件时,也许我必须做一些特别的事情。我只是使用:
make clean html && make html
Run Code Online (Sandbox Code Playgroud)
我的conf.py位于:root/source/conf.py。以下是我的conf.py文件的一些摘录:
import sphinx_rtd_theme
project = 'Project Name'
copyright = '2021, My Company'
author = 'My Name, Coworker Name'
master_doc = 'Home'
extensions = ["sphinx_rtd_theme", "sphinx.ext.todo"]
todo_include_todos = True
templates_path = ['_templates']
source_suffix = ['.rst']
html4_writer = True
html_theme = 'sphinx_rtd_theme'
# html_theme_path = ['_static']
html_static_path = ['_static']
# html_extra_path = []
html_show_sphinx = True
html_show_copyright = True
html_style = 'css/my_theme.css'
Run Code Online (Sandbox Code Playgroud)
这是layout.html我已覆盖的文件。它位于评论中显示的路径中。
<!-- layout.html
* Place this file in root/source/_templates
* -->
{% extends "!layout.html" %}
{% block extrahead %}
{{super}}
<link href="{{ pathto("_static/my_theme.css", True) }}" rel="stylesheet" type="text/css">
{% endblock %}
{% block extrafooter %}
{{super}}
<div class="footer">
My custom footer just needs to add a single sentance to the existing footer.
</div>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
小智 6
您想添加自定义页脚还是替换默认页脚?就我而言,我只需要覆盖footer.html文件而不是 layout.html。
以下是我为 Sphinx 文档所做的 100% 有效的操作:
{% extends "!footer.html" %}
{%- block contentinfo %}
{{ super }}
<!-- your custom footer here-->
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
请注意页脚实际包含在哪个块中。就我而言,它位于contentinfo内部