Skip to content

A rails-style time_ago_in_words filter for the liquid templating language

Notifications You must be signed in to change notification settings

albrow/liquid_time_ago_in_words

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Liquid time_ago_in_words

(v 1.0.1)

A rails-style time_ago_in_words filter for the liquid templating language. Intended for use for people who use liquid without rails (e.g. a Jekyll or Octopress blog). If you're using liquid with rails, you don't need this!

The code is based on Klaus Byskov Hoffmann's language-agnostic version.

Installation

In your plugins directory:

curl -L -O https://github.com/albrow/liquid_time_ago_in_words/raw/master/time_ago_in_words.rb

or

wget https://github.com/albrow/liquid_time_ago_in_words/raw/master/time_ago_in_words.rb

Don't forget to restart your server!

Usage

It works like any other filter:

{{ page.date | time_ago_in_words }}

The output looks like 14 minutes ago or about a day ago or etc.

Adding Javascript Functionality

By default, the time ago will only update everytime you run rake generate. If you don't regenerate your site often, this could result in the time ago becoming outdated. To fix that problem, I've included a small snippet of javascript that will update the time ago client-side. It has no dependencies, but it's not guaranteed to work in older browsers.

To add this functionality to your site, simply pull the time_ago.js file (or just copy and paste it) and add it to your javascript directory. Don't forget to add <script src="{{ root_url }}/javascripts/time_ago.js"></script> somewhere.

About

A rails-style time_ago_in_words filter for the liquid templating language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published