如何在Sphinx文档生成器中修改html标题分隔符

bihw5rsg  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(192)

默认情况下,似乎使用长划线'--'作为页面标题和整个网站html_title之间的分隔符,这是在www.example.com文件中设置config.py的。
我们想将其更改为"|'字符。
我可以在layout.html模板中添加一个块来修改标题,我只是不确定该写什么。我希望它是'page_title| html_title'的标题标签。

iq3niunx

iq3niunx1#

长破折号(—)来自layout.html模板:

{%- if not embedded and docstitle %}
{%- set titlesuffix = " — "|safe + docstitle|e %}
{%- else %}
{%- set titlesuffix = "" %}
{%- endif %}

titlesuffix的值在模板中稍靠后的位置使用:

{%- block htmltitle %}
<title>{{ title|striptags|e }}{{ titlesuffix }}</title>
{%- endblock %}

要自定义:
1.确保conf.py中有templates_path = ['_templates']
1.在_templates目录中建立名为layout.html的档案。
1.在layout.html中,添加以下内容:

{% extends "!layout.html" %}

{%- set customtitlesuffix = " | "|safe + docstitle|e %}

{%- block htmltitle %}
<title>{{ title|striptags|e }}{{ customtitlesuffix }}</title>
{%- endblock %}

另请参阅https://www.sphinx-doc.org/en/master/templating.html

相关问题