Jekyll排序为字符串,应为日期

Jekyll排序为字符串,应为日期,jekyll,prose,Jekyll,Prose,我将Jekyll与散文结合使用,并设置了一个额外的元数据,名为pub_date 在散文中,这设置为文本字段(日期时间字段尚不受支持) 用户为pub_date输入类似于2015-01-23的内容,我可以获取此值并通过date方法运行它以正确输出日期(例如{{post.pub_date | date:“%b%-d,%Y”}works) 当我尝试对这些值进行排序时,它们被视为字符串 {% assign sorted_posts = (paginator.posts | sort: 'pub_date'

我将Jekyll与散文结合使用,并设置了一个额外的元数据,名为pub_date

在散文中,这设置为文本字段(日期时间字段尚不受支持)

用户为pub_date输入类似于2015-01-23的内容,我可以获取此值并通过date方法运行它以正确输出日期(例如
{{post.pub_date | date:“%b%-d,%Y”}
works)

当我尝试对这些值进行排序时,它们被视为字符串

{% assign sorted_posts = (paginator.posts | sort: 'pub_date', 'first') %}
有没有更好的方法来整理这些收藏?或者,我可以做些什么来强制该值像日期一样


我正在使用github页面托管解决方案,因此很遗憾,我们无法对Jekyll执行任何自定义操作。

正确的语法对您的
分页器进行排序。按
发布日期发布

{% assign sorted_posts = paginator.posts | sort: 'pub_date' %}

{% for post in sorted_posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">Pubdate : {{ post.pub_date | date: "%b %-d, %Y"}}</span>
  </p>
{% endfor %}

使用正确的语法对您的
分页器进行排序。按
发布日期发布

{% assign sorted_posts = paginator.posts | sort: 'pub_date' %}

{% for post in sorted_posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">Pubdate : {{ post.pub_date | date: "%b %-d, %Y"}}</span>
  </p>
{% endfor %}

使用正确的语法对您的
分页器进行排序。按
发布日期发布

{% assign sorted_posts = paginator.posts | sort: 'pub_date' %}

{% for post in sorted_posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">Pubdate : {{ post.pub_date | date: "%b %-d, %Y"}}</span>
  </p>
{% endfor %}

使用正确的语法对您的
分页器进行排序。按
发布日期发布

{% assign sorted_posts = paginator.posts | sort: 'pub_date' %}

{% for post in sorted_posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">Pubdate : {{ post.pub_date | date: "%b %-d, %Y"}}</span>
  </p>
{% endfor %}

使用带引号的字符串作为参数进行排序时出错将Jekyll::Post与Jekyll::Post进行比较失败

相反,使用以下方法是有效的

{% assign sorted_posts = paginator.posts | sort: :pub_date | reversed %}
{% assign latest_post = sorted_posts | last %}

<!-- do something with latest post -->

{% for post in sorted_posts reversed %}
{% if forloop.first %}<!-- discard the first post -->{% else %}

<!-- iterate over posts -->

{% endif %}
{% endfor %}
{%assign sorted_posts=paginator.posts | sort::pub_date | reversed%}
{%assign latest_post=sorted_posts | last%}
{已排序的_posts中的post%已反转%}
{%if-forloop.first%}{%else%}
{%endif%}
{%endfor%}

不是100%确定为什么需要调用reverse两次,但它可以工作。

我在使用带引号的字符串作为参数进行排序时出错将Jekyll::Post与Jekyll::Post进行比较失败

相反,使用以下方法是有效的

{% assign sorted_posts = paginator.posts | sort: :pub_date | reversed %}
{% assign latest_post = sorted_posts | last %}

<!-- do something with latest post -->

{% for post in sorted_posts reversed %}
{% if forloop.first %}<!-- discard the first post -->{% else %}

<!-- iterate over posts -->

{% endif %}
{% endfor %}
{%assign sorted_posts=paginator.posts | sort::pub_date | reversed%}
{%assign latest_post=sorted_posts | last%}
{已排序的_posts中的post%已反转%}
{%if-forloop.first%}{%else%}
{%endif%}
{%endfor%}

不是100%确定为什么需要调用reverse两次,但它可以工作。

我在使用带引号的字符串作为参数进行排序时出错将Jekyll::Post与Jekyll::Post进行比较失败

相反,使用以下方法是有效的

{% assign sorted_posts = paginator.posts | sort: :pub_date | reversed %}
{% assign latest_post = sorted_posts | last %}

<!-- do something with latest post -->

{% for post in sorted_posts reversed %}
{% if forloop.first %}<!-- discard the first post -->{% else %}

<!-- iterate over posts -->

{% endif %}
{% endfor %}
{%assign sorted_posts=paginator.posts | sort::pub_date | reversed%}
{%assign latest_post=sorted_posts | last%}
{已排序的_posts中的post%已反转%}
{%if-forloop.first%}{%else%}
{%endif%}
{%endfor%}

不是100%确定为什么需要调用reverse两次,但它可以工作。

我在使用带引号的字符串作为参数进行排序时出错将Jekyll::Post与Jekyll::Post进行比较失败

相反,使用以下方法是有效的

{% assign sorted_posts = paginator.posts | sort: :pub_date | reversed %}
{% assign latest_post = sorted_posts | last %}

<!-- do something with latest post -->

{% for post in sorted_posts reversed %}
{% if forloop.first %}<!-- discard the first post -->{% else %}

<!-- iterate over posts -->

{% endif %}
{% endfor %}
{%assign sorted_posts=paginator.posts | sort::pub_date | reversed%}
{%assign latest_post=sorted_posts | last%}
{已排序的_posts中的post%已反转%}
{%if-forloop.first%}{%else%}
{%endif%}
{%endfor%}
不是100%确定为什么我们需要调用reverse两次,但它是有效的