1

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

我怎样才能做到这一点?

4

1 回答 1

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.

于 2015-09-17T11:10:26.040 回答