Jekyll x Liquid: 文章置顶功能的实现

    xiaoxiao2021-03-26  23

    今天突然闲的蛋疼想把一些文章置顶, 于是就研究了一下如何实现, 还顺便把功能塞到了前段时间发布的- Jekyll主题 里面

    两个方案:

    Server端实现Client端实现

    Server端实现

    其实很简单, 一开始以为无法对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 %}

    Client端实现

    我太懒了没去研究 o( ̄▽ ̄)o

    用JQuery.sort()给DOM排序再渲染一下即可

    这个排序还要额外对时间进行比较//果然懒一点是没错的 o( ̄▽ ̄)o

    演示页面

    szhshp的第三边境研究所

    参考

    Jekyll原创主题Project Gaia Jekyll x Liquid 控制文章列表只显示特定类别的Post
    转载请注明原文地址: https://ju.6miu.com/read-661189.html

    最新回复(0)