Jekyll-Timeago
Custom and simple implementation of timeago date filter. Futures and personalization are also supported.
In fact, jekyll-timeago is an extension of Liquid filters, so you can use it in all your Liquid templates.
Installation
Add this gem to your Gemfile and run bundle:
gem 'jekyll-timeago'
To use this filter, just add the following to the top of another plugin (found under _plugins/):
require 'jekyll/timeago'
Alternatively, you can simply copy this file directly into your _plugins/ directory! :)
Usage
<span>{{ page.date | timeago }}</span>
<h2>{{ page.title }}</h2>
<div class="post">
{{ content }}
</div>
Customization
You can personalize the level of detail (from 1 up to 4, 2 by default) passing a parameter:
<span>{{ page.date | timeago: 4 }}</span>
Output Examples
Default behavior:
> timeago(Date.today)
=> "today"
> timeago(Date.today - 1.day)
=> "yesterday"
> timeago(Date.today - 10.days)
=> "1 week and 3 days ago"
> timeago(Date.today - 100.days)
=> "3 months and 1 week ago"
> timeago(Date.today - 500.days)
=> "1 year ago and 4 months ago"
> timeago(Date.today + 1.days)
=> "tomorrow"
> timeago(Date.today + 7.days)
=> "in 1 week"
Change level of detail to get higher or lower granularity:
> timeago(Date.today - 500.days) # default
=> "1 year ago and 4 months ago"
> timeago(Date.today - 500.days, 3)
=> "1 year and 4 months and 1 week ago"
> timeago(Date.today - 500.days, 4)
=> "1 year and 4 months and 1 week and 4 days ago"
> timeago(Date.today - 500.days, 1)
=> "1 year ago"
License
Copyright (c) 2013 Marc Anguera. Unscoped Associations is released under the MIT License.