Created
June 4, 2013 11:19
-
-
Save WheresWardy/5705223 to your computer and use it in GitHub Desktop.
Jekyll/Liquid plugin to add an ordinal suffix to dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can then adjust strftime to give you a date of your liking, chucking in
#{ord}
wherever you need it, and include the date like so:{{ post.date | date_post }}