JBake模板:突出显示最新帖子

时间:2015-09-16 07:43:56

标签: freemarker jbake jbake-templates

我是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>

我怎样才能做到这一点?

1 个答案:

答案 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

相关问题