今天突然闲的蛋疼想把一些文章置顶, 于是就研究了一下如何实现, 还顺便把功能塞到了前段时间发布的- Jekyll 主题 里面
两个方案:
其实很简单, 一开始以为无法对 Post 进行操作, 后来发现可以从 post 的 header 里面进行参数设置
layout: post title: 《 10101 》 EP0 :我太受欢迎了该怎么办 category : Comic tags : [Comic, 10101] stickie: true
然后 liquid 进行判断
{* for post in site.posts *} {* if post.stickie != true *} {* continue *} {* endif *} <div>置顶文章细节</div> {* endfor *} {* for post in site.posts *} {* if post.stickie == true *} {* continue *} {* endif *} <div>普通文章细节</div> {* endfor *}
当然这个可以进行多种扩展, 比如只输出特定类别的文章等等,这里就是个只输出带有 comic 这个 tag 的 post
{% for post in site.posts %} {% assign isComic = 0 %} {% for tag in post.tags %} {% if tag == comic %} {% assign isComic = 1 %} {% endif %} {% endfor %} {% if isComic == 0 %} {% continue %} {% endif %} {% endfor %}
我太懒了没去研究 o( ̄ ̄)o
用 JQuery.sort()给 DOM 排序再渲染一下即可
这个排序还要额外对时间进行比较 //果然懒一点是没错的 o( ̄ ̄)o