Menu

Category

Archive

logo


Adding a new filiter for Jekyll (Deprecated articles keeper)

2014-04-29 09:00:00 +0900
  • このエントリーをはてなブックマークに追加

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 module Jekyll
 2  module RenderDeprecate
 3  
 4      def render_deprecate(pageTime, numOfMonth)
 5     
 6      if pageTime == nil
 7          return
 8      end
 9   
10      currentMonths = (Time.now.year*12) + (Time.now.mon)
11      articleMonths = (pageTime.year*12) + (pageTime.mon)   
12      diffMonth     = currentMonths - articleMonths
13      
14      if diffMonth >= numOfMonth
15          "<span class=\"deprecate\">This article might be too old.</span>"
16      else
17          ""
18      end
19  
20      end
21    
22  end
23 end
24 Liquid::Template.register_filter(Jekyll::RenderDeprecate)