Jekyll 以排除某些内容为条件截断博客文章的数量
Jekyll truncate number of blog posts conditional on excluding some
在我的 Jekyll 网站上,我有一个概述页面,上面列出了我最近的 10 篇博文。
不过,我还为我的一些博文和我不想显示的博文分配了标签 exclude
。这行得通,但是我没有得到最后 10 篇博客文章,而是 10 减去 exclude
博客文章的数量。
这是它的样子:
---
layout: page
title: "Last posts"
permalink: /last/
---
### Last posts
{% for post in site.posts limit:10 %}
{% unless post.category == "exclude"%}
* {{ post.date | date_to_string }} » [ {{ post.title }} ]({{ post.url }})
{% endunless %}
{% endfor %}
如何始终显示最近 10 篇非exclude
博文?
显示最近 10 篇非排除博客文章:
创建一个包含不包含 exclude
标签的帖子的数组。
{% assign nonexcludeposts = ''|split:''%}
{% for post in site.posts %}
{% unless post.category == "exclude"%}
{% assign nonexcludeposts = nonexcludeposts|push:post%}
{% endunless %}
{% endfor %}
显示 10 个最新帖子
<ul>
{% for post in nonexcludeposts limit:10 %}
<li>
<a href="{{post.url|absolute_url}}">{{post.title}}</a>
</li>
{% endfor %}
</ul>
在我的 Jekyll 网站上,我有一个概述页面,上面列出了我最近的 10 篇博文。
不过,我还为我的一些博文和我不想显示的博文分配了标签 exclude
。这行得通,但是我没有得到最后 10 篇博客文章,而是 10 减去 exclude
博客文章的数量。
这是它的样子:
---
layout: page
title: "Last posts"
permalink: /last/
---
### Last posts
{% for post in site.posts limit:10 %}
{% unless post.category == "exclude"%}
* {{ post.date | date_to_string }} » [ {{ post.title }} ]({{ post.url }})
{% endunless %}
{% endfor %}
如何始终显示最近 10 篇非exclude
博文?
显示最近 10 篇非排除博客文章:
创建一个包含不包含
exclude
标签的帖子的数组。{% assign nonexcludeposts = ''|split:''%} {% for post in site.posts %} {% unless post.category == "exclude"%} {% assign nonexcludeposts = nonexcludeposts|push:post%} {% endunless %} {% endfor %}
显示 10 个最新帖子
<ul> {% for post in nonexcludeposts limit:10 %} <li> <a href="{{post.url|absolute_url}}">{{post.title}}</a> </li> {% endfor %} </ul>