diff options
author | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-11-04 08:11:16 +0100 |
---|---|---|
committer | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-11-04 08:11:16 +0100 |
commit | 142681489f1a2aad7bc9f225ec7d7a0c1c476e09 (patch) | |
tree | 3c59ac82a0644745c9729cd87cbd355e817fd49c | |
parent | 987dccee7655a410a2fb1e0f41c35b282b17cbe9 (diff) | |
download | my_new_personal_website-142681489f1a2aad7bc9f225ec7d7a0c1c476e09.tar.xz my_new_personal_website-142681489f1a2aad7bc9f225ec7d7a0c1c476e09.zip |
Add custom date format %o for ordinal representation of the day
-rw-r--r-- | _config.yml | 5 | ||||
-rw-r--r-- | plugins/date.rb | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/_config.yml b/_config.yml index fed545c5..e019157f 100644 --- a/_config.yml +++ b/_config.yml @@ -11,6 +11,7 @@ simple_search: http://google.com/search # Default date format is "ordinal" (resulting in "July 22nd 2007") # You can customize the format as defined in # http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime +# Additionally, %o will give you the ordinal representation of the day date_format: "ordinal" # RSS / Email (optional) subscription links (change if using something like Feedburner) @@ -92,6 +93,6 @@ disqus_show_comment_count: false # Google Analytics google_analytics_tracking_id: - + # Facebook Like -facebook_like: true +facebook_like: true diff --git a/plugins/date.rb b/plugins/date.rb index c1c69551..8758f23f 100644 --- a/plugins/date.rb +++ b/plugins/date.rb @@ -29,12 +29,16 @@ module Octopress end end + # Formats date either as ordinal or by given date format + # Adds %o as ordinal representation of the day def format_date(date, format) date = datetime(date) if format.nil? || format.empty? || format == "ordinal" date_formatted = ordinalize(date) else + format.gsub!(/%o/, '%%o') date_formatted = date.strftime(format) + date_formatted.gsub!(/%o/, ordinal(date.strftime('%e').to_i)) end date_formatted end |