如何在readthedocs上覆盖模板?

3

最近我在readthedocs上添加了blowdrycss的sphinx文档

我想要覆盖readthedocs上的layout.html模板。我的当前模板覆盖在localhost上运行良好,但在readthedocs上却不行。该项目使用了扩展基本主题的Alabaster主题。

项目目录结构可以在这里看到。

相关部分如下:

blowdrycss/
    docs/
        _templates/
            layout.html

        conf.py

conf.py中的模板设置:

templates_path = ['_templates']

layout.html的内容:

{% extends '!layout.html' %}


{% block sidebarsearch %}
    {{ super() }}
    <a href="https://flattr.com/submit/auto?user_id=nueverest&url=https%3A%2F%2Fgithub.com%2Fnueverest%2Fblowdrycss" target="_blank"><img src="http://button.flattr.com/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a>
{% endblock %}


{% block footer %}
    <div class="footer" style="text-align: center;">
        <a href="https://flattr.com/submit/auto?user_id=nueverest&url=https%3A%2F%2Fgithub.com%2Fnueverest%2Fblowdrycss" target="_blank"><img src="http://button.flattr.com/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a>
    </div>
    {{ super() }}
{% endblock %}

我如何在readthedocs上覆盖layout.html模板? 更新: 我也尝试过: 相关部分如下:
blowdrycss/
    docs/
        custom_templates/
            layout.html

        conf.py

conf.py中的模板设置:

templates_path = ['custom_templates']

_templates 是默认的模板,你能试试其他的吗? - Ciro Pedrini
我创建了一个名为 custom_templates 的新目录,并将 layout.html 放置在其中。然而,Readthedocs 仍然无法识别它。 - nu everest
它实际上在read-the-docs上有文档记录 http://read-the-docs.readthedocs.org/en/latest/theme.html - Wolph
@Wolph 我正在使用Alabaster主题而不是rtd主题。 - nu everest
@nueverest:我指的是这一段:“默认情况下,Read the Docs将使用自己的自定义sphinx主题,除非您在conf.py文件中设置了自己的主题。” - Wolph
2个回答

3

虽然readthedocs不直接支持templates_path,但你可以使用内部置有模板的自定义主题。http://sphinx-doc.org/theming.html

只需创建一个新的主题目录并将其添加到你的conf.py中:

html_theme = 'your_theme'
html_theme_path = ['.']

您可以在我的项目中看到一个示例: 以上链接为it技术相关内容,希望您能够理解并从中受益。

我使用了 html_theme_path = ['custom_themes', ],将 alabaster 主题复制并粘贴到其中,将其重命名为 custom_alabaster 并编辑了模板文件。感谢您指引我正确的方向。 - nu everest


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接