我建立了一个博客,并想将特定的元数据添加到博客中的每篇文章中。
在每一页的开头我都有以下代码(经过简化以明确我要问的问题)。
---
layout: default
title: "Title"
date: 2018-04-19
---
关闭并在 _layout 中拉入我的 default.html
默认.html
<!DOCTYPE html>
<html lang="en-us">
{% include head.html %}
<body>
</body>
</html>
head.html 是我网站的头部部分。在那里,每个页面上都有一些我想要的通用标题数据。 我想问的是,使用 Jekyll 和 liquid 向每个帖子添加页面/帖子特定元数据的好方法是什么(除了我已经为整个网站准备的一般元数据)?我应该在流程中的哪个位置添加此页面/发布特定元数据?
谢谢!
最佳答案
所以做了一些更多的网络搜索并能够找到以下内容。 (因此,以下代码片段全部归功于该网站。)这是对我最初问题的直接回答,但 Andrei 确实提供了一个很好的观点(见下文)。
https://ehelion.com/blog/2018/02/24/adding-meta-keywords-jekyll.html
将此添加到 head.html:
{% if page.keywords %}
<meta name="keywords" content="{{ page.keywords | join: ', ' | escape }}">
{% endif %}
将此添加到 YAML 字体问题:
---
layout: post
title: "Best blog post ever made"
date: 2029-01-01 16:20:00
keywords:
- some keyword
- another keyword
- get rich quick
---
还要感谢 Andrei Gheorghiu 提供该链接,因为它说明搜索引擎不再真正关心关键字标签了。相反,焦点已经转移到元描述上。但是可以应用相同类型的代码。只需将 if page.keywords 换成 if page.description 并在 YAML 字体中添加描述即可。
关于html - 在 Jekyll 中添加特定于每个帖子的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50079063/