ruby – 如何在Jekyll的主页上按日期分组帖子?

在Jekyll,我希望我的主页列出按日期分组的最新帖子,如下所示:

2013年9月6日

>发布1
>帖子2
>发布3

2013年9月5日

>发布1
>帖子2

基本上,我只想在循环中的帖子与之前处理的日期不同时吐出日期标题.我试图通过测试for循环中的下一篇文章是否匹配上一篇文章的日期来做到这一点,并且只有当它没有时才显示日期标题.这就是我的Liquid模板的样子:

---
layout: default
title: Home Page
---

{% assign thedate = '' %}

{% for post in site.posts %}

    {% if thedate != post.date | date: "%m-%d-%Y" %}
        <h2>{{ post.date | date: "%A,%B %e,%Y" }}</h2>
    {% endif %}

    {% assign thedate = post.date | date: "%m-%d-%Y" %}

    <h3 class="headline"><a href="{{ post.url }}">{{ post.title }}</a></h3>
    {{ post.content }}
    <hr>

{% endfor %}

如果不使用post.date |日期:“%m-%d-%Y”我改为简单地说post.date它有效,并且帖子被组合在一起,但仅当帖子具有完全相同的日期和时间(不仅仅是月份的同一天) .这就是为什么我添加更具体的post.date |日期:“%m-%d-%Y”.

有任何想法吗?非常感谢我们的帮助!!

解决方法

通过修改存档解决方案找到答案: http://www.mitsake.net/2012/04/archives-in-jekyll/

这是有效的代码

layout: default
title: Home Page
---

{% for post in site.posts %}

    {% capture day %}{{ post.date | date: '%m%d%Y' }}{% endcapture %}
    {% capture nday %}{{ post.next.date | date: '%m%d%Y' }}{% endcapture %}

    {% if day != nday %}
        <h5 class="date">{{ post.date | date: "%A,%Y" }}</h5>
    {% endif %}
    {{ post.content }}
    <hr>

{% endfor %}

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...