使用自定义 post.variable 计数帖子
Count posts with custom post.variable
我使用 Hexo hexo.io,但我想 Jekyll 用户可能也知道这个,因为它很相似。
我的 custom.post.variable
是 fruit
。
所以我的 .md
文件有:
title: food
fruit: apple
和
title: more food
fruit: banana
和
title: still more food
fruit: banana
和
title: try some food
fruit: banana
和
title: enjoy food
fruit: apple
如何计算fruit: apple
的所有帖子?
我知道我的自定义 post.variable 不是 site
范围的,所以这是我的问题。
我试图将我的 post.fruit
变量作为一个函数放入 site.posts.length
中,但这没有用。
使用 Liquid 遍历 post 的列表。每当 post 将 fruit
字段设置为 apple
,然后递增计数器。
{% assign postCount = 0 %}
{% for post in site.posts %}
{% if post.fruit == "apple" %}
{% assign postCount = postCount | plus: 1 %}
{% endif %}
{% endfor %}
The number of posts with 'fruit: apple' is {{postCount}}
我使用 Hexo hexo.io,但我想 Jekyll 用户可能也知道这个,因为它很相似。
我的 custom.post.variable
是 fruit
。
所以我的 .md
文件有:
title: food
fruit: apple
和
title: more food
fruit: banana
和
title: still more food
fruit: banana
和
title: try some food
fruit: banana
和
title: enjoy food
fruit: apple
如何计算fruit: apple
的所有帖子?
我知道我的自定义 post.variable 不是 site
范围的,所以这是我的问题。
我试图将我的 post.fruit
变量作为一个函数放入 site.posts.length
中,但这没有用。
使用 Liquid 遍历 post 的列表。每当 post 将 fruit
字段设置为 apple
,然后递增计数器。
{% assign postCount = 0 %}
{% for post in site.posts %}
{% if post.fruit == "apple" %}
{% assign postCount = postCount | plus: 1 %}
{% endif %}
{% endfor %}
The number of posts with 'fruit: apple' is {{postCount}}