5

重写Jekyll的Relate功能

 3 years ago
source link: http://www.luzexi.com/2018/07/26/jekyll-related-page
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

重写Jekyll的Relate功能

Jekyll 的 ‘Relate-相关文章’的功能,写的真的不好用。完全表达不了相关文章的含义。

于是打算修一下 Relate 部分的功能。

网上查了很久,很多人在抱怨,但没人把写好的 Relate 放到网上。

唯一一个Jekyll 的 Relate 插件都是渣的要命的那种,根本没法用。

于是就有了重写这个功能的欲望,本想也简单,只是几个for循环而已。

原以为是 Jekyll 是 Ruby 写的,网页上也是 Ruby,还复习了下 Ruby 写法。以前写过很久没用就会忘记。

最后发现网页部分不是Ruby语法呢,而是 Liquid 的语法,一款用 ruby 写的‘模板引擎’。

Liquid github

查了下他的用法,API还真的不多,用起来好难受。比如 for循环 就是个要命的点。还有变量申明和运算,和平常用的语言相差有点大的。

关于Relate功能,我希望是,有最新的文章链接,之前的文章链接和之后的文章链接,让读者能有更大的概率找到自己想要的文章。

写完后的效果如图:

relate功能图

源码如下:

Jekyll Relate github

July 26, 2018 · 前端技术, 其他技术

感谢您的耐心阅读

Thanks for your reading

版权申明

本文为博主原创文章,未经允许不得转载:

重写Jekyll的Relate功能

Copyright attention

Please don't reprint without authorize.

qrcode_for_gzh.jpg

微信公众号,文章同步推送,致力于分享一个资深程序员在北上广深拼搏中对世界的理解

QQ交流群: 777859752 (高级程序书友会)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK