文章置顶功能的实现 - 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 *}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
上一篇 :七牛云上传图片 - 客户端
下一篇 :扩展篇 :开发框架及前景