我无法在 Jekyll 中获得 site.tags[some_tag].size
I can't get site.tags[some_tag].size in Jekyll
我试过在我的 jekyll 博客中显示标签云,如下所示
https://superdevresources.com/tag-cloud-jekyll/
但是,我无法访问 tag.tags.size
这是sidebar.html
的代码
{% assign tags = site.tags | sort %}
{% for tag in tags %}
<span>
<a href="/tags/{{ tag.slug }}" class="tag-reverse">
<span>{{ tag.name }}</span>
<span>({{ tag.tags.size }})</span>
^ This is always null
</a>{% unless forloop.last %}{% endunless %}
</span>
{% endfor %}
我认为 size
of tag.tags
代表特定标签中的帖子数。但是null总是来的,即使标签中有帖子
仅供参考,这是 _config.xml
的一部分
# Tags
collections:
tags:
output: true
permalink: /tags/:path/
defaults:
- scope:
path: ''
type: tags
values:
layout: tag
您可以在 https://github.com/closer27/closer27.github.io
访问我的博客存储库
谢谢你帮助我
理想情况下 site.tags
会由您使用过的标签填充。但是在你的情况下,它被你的 _tags
collection.
覆盖了
没关系,因为你只有一个 collection (_posts
),你可以生成 tag-size 如下:
{% for tag in site.tags %}
<span>
<a href="/tags/{{ tag.slug }}" class="tag-reverse">
<span>{{ tag.name }}</span>
<span>
({{ site.posts | where_exp: 'post', 'post.tags contains tag.name' | size }})
</span>
</a>
</span>
{% endfor %}
我试过在我的 jekyll 博客中显示标签云,如下所示
https://superdevresources.com/tag-cloud-jekyll/
但是,我无法访问 tag.tags.size
这是sidebar.html
{% assign tags = site.tags | sort %}
{% for tag in tags %}
<span>
<a href="/tags/{{ tag.slug }}" class="tag-reverse">
<span>{{ tag.name }}</span>
<span>({{ tag.tags.size }})</span>
^ This is always null
</a>{% unless forloop.last %}{% endunless %}
</span>
{% endfor %}
我认为 size
of tag.tags
代表特定标签中的帖子数。但是null总是来的,即使标签中有帖子
仅供参考,这是 _config.xml
# Tags
collections:
tags:
output: true
permalink: /tags/:path/
defaults:
- scope:
path: ''
type: tags
values:
layout: tag
您可以在 https://github.com/closer27/closer27.github.io
访问我的博客存储库谢谢你帮助我
理想情况下 site.tags
会由您使用过的标签填充。但是在你的情况下,它被你的 _tags
collection.
没关系,因为你只有一个 collection (_posts
),你可以生成 tag-size 如下:
{% for tag in site.tags %}
<span>
<a href="/tags/{{ tag.slug }}" class="tag-reverse">
<span>{{ tag.name }}</span>
<span>
({{ site.posts | where_exp: 'post', 'post.tags contains tag.name' | size }})
</span>
</a>
</span>
{% endfor %}