我是JBake的新手。我看到了创建索引页面的默认方式。
<#list posts as post>
<#if (post.status == "published")>
-- design your posts here
</#if>
</#list>
这会按降序排列所有帖子。
这看起来很棒,只有一个问题,我不知道如何突出我的最新帖子。
所以我想做点什么,
<#list posts as post>
<#if (post.status == "published")>
<#if (this is latest post)>
use highlighted style
</#if>
<#if (this is not a latest post)>
use normal style
</#if>
</#if>
</#list>
我怎样才能做到这一点?
答案 0 :(得分:4)
这是一个适用于JBake v2.4.0的解决方案:
<#list posts as post>
<#if (post.status == "published")>
<#if (post_index == 0)>
//apply highlight style
<#else>
//apply normal style
</#if>
</#if>
</#list>
要加快页面的渲染速度,您也可以使用published_posts
变量:
<#list published_posts as post>
<#if (post.status == "published")>
<#if (post_index == 0)>
//apply highlight style
<#else>
//apply normal style
</#if>
</#if>
</#list>
如果您更新JBake以使用Freemarker v2.3.23,则可以使用post?is_first
代替post_index == 0
。