文章置顶功能的实现 - Jekyll x Liquid
基础版
其实很简单, 从post的header里面进行参数设置
layout: post
title: Jekyll x Liquid: 文章置顶功能的实现
category: 个人博客
tags: [个人博客,Jekyll,文章置顶,gorpeln]
description: 
top: true
然后liquid进行判断(*号换成%)
{* for post in site.posts *}
    {* if post.top != true *}
        {* continue *}
    {* endif *}
    <div>置顶文章细节</div>
{* endfor *}
{* for post in site.posts *}
    {* if post.top == true *}
        {* continue *}
    {* endif *}
    <div>普通文章细节</div>
{* endfor *}
当然这个可以进行多种扩展, 比如只输出特定类别的文章等等,这里就是个只输出带有gorpeln这个tag的post
{* for post in site.posts *}
    {* assign isGorpeln = 0 *}
    {* for tag in post.tags *}
        {* if tag == gorpeln *}
           {* assign isGorpeln = 1 *}
        {* endif *}
    {* endfor *}
    {* if isGorpeln == 0 *}
      {* continue *}
    {* endif *}
{* endfor *}
升级版
(*号换成%)
{* comment *} 置顶文章列表开始 {* endcomment *}
{* for post in site.posts *}
{* if post.top *}
{* if paginator.page == 1 *}
{* comment *} 文章列表代码开始 {* endcomment *}
<!-- 在这里写文章列表代码 -->
{* comment *} 文章列表代码结束 {* endcomment *}
{* endif *}
{* endif *}
{* endfor *}
{* comment *} 置顶文章列表结束 {* endcomment *}
  
  
{* comment *} 普通文章列表开始 {* endcomment *}
{* for post in paginator.posts *}
{* if post.top *}
{* else *}
{* comment *} 文章列表代码开始 {* endcomment *}
<!-- 在这里写文章列表代码 -->
{* comment *} 文章列表代码结束 {* endcomment *}
{* endif *}
{* endfor *}
{* comment *} 普通文章列表结束 {* endcomment *}
 
                  
                 
                   
                   
                  