I’ve working on making my personal blog through Jekyll, recently. There I made a simple plugin which can guarantee a blog post’s validity for certain terms.
How to use it
It’s super easy to use, code below:
{{ page.date render_deprecate: 6 }}
For example, you can put this code on the uppermost of your post. This code will say “This article might be too old” after 6 months. Jekyll is a static blog engine. Hence, the time of the post passing 6 months is determined by the time you build the blog.
Code
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | module Jekyll module RenderDeprecate def render_deprecate(pageTime, numOfMonth) if pageTime == nil return end currentMonths = (Time.now.year*12) + (Time.now.mon) articleMonths = (pageTime.year*12) + (pageTime.mon) diffMonth = currentMonths - articleMonths if diffMonth >= numOfMonth "<span class=\"deprecate\">This article might be too old.</span>" else "" end end end end Liquid::Template.register_filter(Jekyll::RenderDeprecate) |