如何在Jekyll中显示前N篇文章

如何在Jekyll中显示前N篇文章,jekyll,liquid,Jekyll,Liquid,我正在使用Jekyll2作为我的博客。我还使用显示主页中的前5篇文章 现在我想停止使用jekyll paginate,因为它会用我不想要的页面污染网站地图 以下是删除分页后我的主页的外观: --- layout: default --- <div class="blog-index"> {% assign index = true %} {% for post in site.posts %} {% assign content = post.content %}

我正在使用Jekyll2作为我的博客。我还使用显示主页中的前5篇文章

现在我想停止使用jekyll paginate,因为它会用我不想要的页面污染网站地图

以下是删除分页后我的主页的外观:

---
layout: default
---

<div class="blog-index">
  {% assign index = true %}
  {% for post in site.posts %}
  {% assign content = post.content %}
    <article>
      {% include article.html %}
    </article>
  {% endfor %}
</div>
---
布局:默认值
---
{%assign index=true%}
{site.posts%中的post为%s}
{%assign content=post.content%}
{%include article.html%}
{%endfor%}
这将显示所有帖子,但我只想要前5篇。在Ruby中,您可以执行
.take(5)
.first(5)
,所以我尝试了,但没有成功


如何仅显示最近的5篇文章?

您可以在
for
循环中使用
limit
参数来执行此操作:


{% for post in site.posts limit:5 %}
   <article>
      {% include article.html %}
    </article>
{% end %}

{站点中帖子的百分比。帖子限制:5%}