All Projects → markets → Jekyll Timeago

markets / Jekyll Timeago

Licence: mit
⌛️ Ruby library to compute distance of dates in words. Originally built for Jekyll.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Jekyll Timeago

Gojekyll
A fast clone of the Jekyll blogging engine, in Go
Stars: ✭ 62 (-52.31%)
Mutual labels:  jekyll, liquid
Glim
Static site generator which is semi-compatible with Jekyll
Stars: ✭ 76 (-41.54%)
Mutual labels:  jekyll, liquid
Jekyll Minibundle
A minimalistic asset bundling plugin for Jekyll
Stars: ✭ 65 (-50%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll Liquify
A Jekyll filter that parses Liquid from front matter
Stars: ✭ 21 (-83.85%)
Mutual labels:  jekyll, liquid
Garth
🥁 A really basic theme for Jekyll
Stars: ✭ 85 (-34.62%)
Mutual labels:  jekyll, liquid
Jekyll Timeline
Timeline / Résumé Theme with Jekyll
Stars: ✭ 46 (-64.62%)
Mutual labels:  jekyll, liquid
Jekyll Katex
Jekyll plugin for easy server-side math rendering via KaTeX
Stars: ✭ 73 (-43.85%)
Mutual labels:  jekyll, jekyll-plugin
Alembic
⚗️ A Jekyll boilerplate theme designed to be a starting point for any Jekyll website
Stars: ✭ 501 (+285.38%)
Mutual labels:  jekyll, liquid
Jekyll Menus
A menus (site navigation) plugin for your Jekyll website that also works with https://forestry.io (Jekyll CMS)
Stars: ✭ 115 (-11.54%)
Mutual labels:  jekyll, liquid
Jekyll Seo Tag
A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content.
Stars: ✭ 1,226 (+843.08%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll Scholar
jekyll extensions for the blogging scholar
Stars: ✭ 872 (+570.77%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll
🌐 Jekyll is a blog-aware static site generator in Ruby
Stars: ✭ 43,803 (+33594.62%)
Mutual labels:  jekyll, liquid
Jekyll Redirect From
🔀 Seamlessly specify multiple redirections URLs for your pages and posts.
Stars: ✭ 630 (+384.62%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll Assets
🎨 Asset pipelines for Jekyll.
Stars: ✭ 1,083 (+733.08%)
Mutual labels:  jekyll, liquid
Jekyll Rss Feeds
Templates for rendering RSS feeds for your Jekyll blog
Stars: ✭ 627 (+382.31%)
Mutual labels:  jekyll, liquid
Rustycrate.ru
Русскоязычный сайт о языке программирования Rust
Stars: ✭ 72 (-44.62%)
Mutual labels:  jekyll, liquid
Jekyll Paginate V2
Pagination Generator for Jekyll 3 (enhanced replacement for the old built-in jekyll-paginate gem) ⛺
Stars: ✭ 412 (+216.92%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll Import
📥 The "jekyll import" command for importing from various blogs to Jekyll format.
Stars: ✭ 424 (+226.15%)
Mutual labels:  jekyll, jekyll-plugin
Jekyll Cloudinary
Jekyll plugin adding a Liquid tag for Cloudinary, for better responsive images
Stars: ✭ 79 (-39.23%)
Mutual labels:  jekyll, jekyll-plugin
Hanuman
A responsive, lightning-fast Jekyll theme built using AMP (Accelerated Mobile Pages) to speed up your blogs and websites.
Stars: ✭ 100 (-23.08%)
Mutual labels:  jekyll, jekyll-plugin

Jekyll-Timeago

Gem Version Build Status Maintainability

A Ruby library to compute distance of dates in words, with localization support. Originally built for Jekyll.

Main features:

  • Compute distance of dates, in words, ie: 1 week and 2 days ago, 5 months ago, in 1 year
  • Future times
  • Out of the box support for Jekyll projects, available as a Liquid Filter and as a Liquid Tag
  • Localization
  • Level of detail customization
  • Command line utility
  • Approximate distance, with customizable threshold, ie: 366 days becomes 1 year ago instead of 1 year and 1 day ago

In fact, jekyll-timeago started as an extension for the Liquid template engine, to be used in Jekyll and Octopress backed sites. But actually, you can use it easily on any Ruby project and even as a tool from the terminal!

Read more about the Jekyll integration in this section.

Installation

Add this line to your application's Gemfile:

gem 'jekyll-timeago'

And then execute:

> bundle install

Or install it yourself as:

> gem install jekyll-timeago

Usage

The gem provides the timeago method:

Jekyll::Timeago.timeago(from, to = Date.today, options = {})

You can include the method in the current context by including the module (so you can call directly the timeago method without using the whole scope):

include Jekyll::Timeago

Examples:

>> timeago(Date.today)
=> "today"
>> timeago(Date.today.prev_day)
=> "yesterday"
>> timeago(Date.today.prev_day(10))
=> "1 week and 3 days ago"
>> timeago(Date.today.prev_day(100))
=> "3 months and 1 week ago"
>> timeago(Date.today.prev_day(500))
=> "1 year and 4 months ago"
>> timeago('2010-1-1', '2012-1-1')
=> "2 years ago"
>> timeago(Date.today.next_day)
=> "tomorrow"
>> timeago(Date.today.next_day(7))
=> "in 1 week"
>> timeago(Date.today.next_day(1000))
=> "in 2 years and 8 months"

NOTE If you have the gem installed in your system globally, and you're not using Bundler (probably because you're are writing a basic script), don't forget to require the library first:

require 'jekyll-timeago'
include Jekyll::Timeago

puts timeago('2030-1-1')

Options

  • locale

To use a different language:

>> timeago(Date.today.prev_day(200), locale: :es)
=> "hace 6 meses y 2 semanas"
>> timeago(Date.today.prev_day(200), locale: :fr)
=> "il y a environ 6 mois et 2 semaines"

Read more about the localization options here.

  • depth

You are able to change the level of detail (from 1 up to 4, 2 by default) to get higher or lower granularity:

>> timeago(Date.today.prev_day(2000), depth: 3)
=> "5 years, 5 months and 3 weeks ago"
>> timeago(Date.today.prev_day(2000), depth: 4)
=> "5 years, 5 months, 3 weeks and 4 days ago"
  • threshold

The next component in the time must at least match this threshold to be picked. Set to 0 by default, so you don't get any approximations. Can be used to drop "straggling" values which are too low to be of any use (in 7 months and 2 days is as good as saying in 7 months).

>> timeago(Date.today.prev_day(366), depth: 2, threshold: 0.05)
=> "1 year ago"

Localization

By default, jekyll-timego already provides translations for some languages. You can check the list here. However, you are able to provide your own translations, or even override the originals, easily.

This project uses the mini_i18n gem under the hood to deal with translations. You can read further about all options in its docs. Example:

MiniI18n.configure do |config|
  config.load_translations('/path_to_your_translations_files/*.yml')
  config.default_locale = :es
end

If you want to contribute and support more default languages, please feel free to send a pull request.

CLI

You can also use jekyll-timeago from the command line:

> jekyll-timeago --help
> jekyll-timeago 2016-1-1
2 years and 6 months ago
> jekyll-timeago 2016-1-1 --locale fr
il y a environ 2 années et 6 mois

Console

Starts a custom IRB session with the timeago method included:

> jekyll-timeago --console
>> timeago(Date.today)
=> "today"

Jekyll integration

You have different options to install and use jekyll-timeago into your Jekyll project:

  • Via Jekyll plugin system

Install the gem to your system:

> gem install jekyll-timeago

In your _config.yml file, add a new array with the key gems and the values of the gem names of the plugins you’d like to use. In this case:

plugins:
  - jekyll-timeago
  • Via Bundler

Add this gem to your Gemfile and run bundle install:

group :jekyll_plugins do
  gem 'jekyll-timeago'
end

Usage

Liquid Filter:

<p>{{ page.date | timeago }}</p>
<p>{{ page.date | timeago: '2020-1-1' }}</p>

Liquid Tag:

<p>{% timeago 2000-1-1 %}</p>
<p>{% timeago 2000-1-1 2010-1-1 %}</p>

Configuration

In your _config.yml file, you can customize the following options:

jekyll_timeago:
  depth: 2
  translations_path: '/path_to_your_translations/*.yaml'
  default_locale: 'en'
  fallbacks: true
  available_locales:
    - 'en'
    - 'es'
    - 'fr'

Also, you can set a different language per page using the Front Matter functionality:

---
locale: 'es'
---

Development

Any kind of feedback, bug report, idea or enhancement are really appreciated.

To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add specs for behaviour changes and run the test suite:

> bundle exec rake

License

Copyright (c) Marc Anguera. Jekyll-Timeago is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].