ianwinter
6/4/2013 - 11:19 AM

Jekyll/Liquid plugin to add an ordinal suffix to dates

Jekyll/Liquid plugin to add an ordinal suffix to dates

module Jekyll
  module DateFilter
    def ord(v)
      (['1', '21', '31'].include?(v) && "st") ||
      (['2', '22'].include?(v) && "nd") ||
      (['3', '23'].include?(v) && "rd") ||
      "th"
    end

    def date_post(postdate)
      ord = ord(postdate.strftime("%-d"))
      postdate.strftime("%-d#{ord} %B %Y")
    end
  end
end

Liquid::Template.register_filter(Jekyll::DateFilter)