我朋友的网站是用 Just the Docs Jekyll 主题制作的,并托管在 GitHub 页面上。
是否可以更改主页的元标题而不更改网站上显示的当前标题?
目前我朋友网站生成的元标题是:
<title>Home - Lea Bosshart Text</title>
在_config.yml文件中有以下内容:
title: Lea Bosshart Text
在网站上看起来像这样:
其实你可以找到这个文件
_includes/title.html
:
{% if site.logo %}
<div class="site-logo" role="img" aria-label="{{ site.title }}"></div>
{% else %}
{{ site.title }}
{% endif %}
值
site.title
是您在元标题中更改的内容。
您可以直接更改为您想要的文本,或者在 metaTitle
中创建一个值,例如 _config.yml
,然后将 site.title
替换为 metaTitle
,并在 metaTitle
中为 _config.yml
赋予值。
更新: 我在上面的解决方案中犯了一个错误。
这个问题的反面也很简单。通过Web Inspector,我们可以发现网页中的标题位于侧边栏标签中。查看文件_layout/default.html,可以发现侧边栏是基于_includes/components/sidebar,查看is文件,可以发现我们要更改的标题是基于_includes/title.html我上面提到过。这意味着两者网站标题和标题标签都是基于
title.html
为了解决这个问题,我们应该知道值
site.title
也可以在其他地方使用,例如footer
标签。
因此,如果您只想标题标签与其他标签不同,您可以创建一个新的
_includes/title_custom.html
,并在sidebar.html
中将
title.html
替换为title_custom.html