Skip to content

Instantly share code, notes, and snippets.

@abarrak
Created October 6, 2016 21:13
Show Gist options
  • Select an option

  • Save abarrak/8be3d4e8dfd6b1b107bf23c58cb296dd to your computer and use it in GitHub Desktop.

Select an option

Save abarrak/8be3d4e8dfd6b1b107bf23c58cb296dd to your computer and use it in GitHub Desktop.
A simple jekyll pluging for simple locale dates
##
# A simple jekyll pluging to distinguish date for :ar and :en languages
# inside the post page.
#
# Usage:
# {% render_date %}
#
# Author: Abdullah Barrak (abarrak)
# License: Unlicensed.
##
require 'date'
module Jekyll
class RenderDateTag < Liquid::Tag
AR_MONTHS = {
Jan: 'يناير',
Feb: 'فبراير',
Mar: 'مارس',
Apr: 'أبريل',
May: 'مايو',
Jun: 'يونيو',
Jul: 'يوليو',
Aug: 'أغسطس',
Sep: 'سبتمبر',
Oct: 'أكتوبر',
Nov: 'نوفمبر',
Dec: 'ديسمبر',
}
def initialize tag_name, text, tokens
super
end
def render context
date = context['page']['date'].strftime("%d %b %Y").to_s
if context['page']['language'] == 'ar'
m = date.split(' ')[1]
date.sub! m, AR_MONTHS[m.to_sym]
end
date
end
end
end
Liquid::Template.register_tag('render_date', Jekyll::RenderDateTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment