液体 page.date 过滤器在 index.html 中不起作用

Liquid page.date filter not working in index.html

我正在使用 Jekyll 和 Liquid 标签来格式化网站。 "page.date" 变量适用于我的 collection 中的页面,但不会在我的根目录中的 index.html 文件中显示日期。这是代码行:

<h6 class="tar">Last update: {{ page.date | date: "%A, %B %-d, %Y" }}</h6>

index.html有什么特别之处吗?我需要使用其他变量来显示此页面的日期吗?

与 collections(帖子是 collection)相反,如果您想将其与 {{ page.date }} 一起使用,页面类型需要在前面注明日期。

重申我的评论,索引页没有附加 date 变量,只有 post 有。日期由前面的 date 标签设置,如果不存在,则从 post 文件名中获取。

在索引页上,要显示上次 post 的日期,您必须使用:

{{ site.posts.first.date | date: "%A, %B %-d, %Y" }}