diff options
-rw-r--r-- | .themes/classic/source/_includes/post/date.html | 9 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/page.html | 2 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/post.html | 6 | ||||
-rw-r--r-- | _config.yml | 5 | ||||
-rw-r--r-- | plugins/date.rb | 69 | ||||
-rw-r--r-- | plugins/octopress_filters.rb | 30 |
6 files changed, 83 insertions, 38 deletions
diff --git a/.themes/classic/source/_includes/post/date.html b/.themes/classic/source/_includes/post/date.html index dbfa67ae..4fb570d2 100644 --- a/.themes/classic/source/_includes/post/date.html +++ b/.themes/classic/source/_includes/post/date.html @@ -1,12 +1,7 @@ {% capture date %}{{ page.date }}{{ post.date }}{% endcapture %} +{% capture date_formatted %}{{ page.date_formatted }}{{ post.date_formatted }}{% endcapture %} {% capture has_date %}{{ date | size }}{% endcapture %} -{% capture updated %}{{ page.updated }}{{ post.updated }}{% endcapture %} -{% capture was_updated %}{{ updated | size }}{% endcapture %} {% if has_date != '0' %} - {% capture time %}<time datetime="{{ date | datetime | date_to_xmlschema }}" pubdate {% if updated %} data-updated="true" {% endif %}>{{ date | ordinalize }}</time>{% endcapture %} + {% capture time %}<time datetime="{{ date | datetime | date_to_xmlschema }}" pubdate>{{ date_formatted }}</time>{% endcapture %} {% endif %} - -{% if was_updated != '0' %} - {% capture updated %}<time class="updated" datetime="{{ updated | datetime | date_to_xmlschema }}">Updated {{ updated | ordinalize }}</time>{% endcapture %} -{% else %}{% assign updated = false %}{% endif %} diff --git a/.themes/classic/source/_layouts/page.html b/.themes/classic/source/_layouts/page.html index 8ba6ec94..7f3b7627 100644 --- a/.themes/classic/source/_layouts/page.html +++ b/.themes/classic/source/_layouts/page.html @@ -15,7 +15,7 @@ layout: default <footer> {% if page.date or page.author %}<p class="meta"> {% if page.author %}{% include post/author.html %}{% endif %} - {% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %} + {% include post/date.html %}{{ time }} {% if page.categories %}{% include post/categories.html %}{% endif %} </p>{% endif %} {% unless page.sharing == false %} diff --git a/.themes/classic/source/_layouts/post.html b/.themes/classic/source/_layouts/post.html index f61d52a8..251e831d 100644 --- a/.themes/classic/source/_layouts/post.html +++ b/.themes/classic/source/_layouts/post.html @@ -9,17 +9,17 @@ single: true <footer> <p class="meta"> {% include post/author.html %} - {% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %} + {% include post/date.html %}{{ time }} {% include post/categories.html %} </p> {% unless page.sharing == false %} {% include post/sharing.html %} {% endunless %} <p class="meta"> - {% if page.previous.url %} + {% if page.previous.url %} <a class="basic-alignment left" href="{{page.previous.url}}" title="Previous Post: {{page.previous.title}}">« {{page.previous.title}}</a> {% endif %} - {% if page.next.url %} + {% if page.next.url %} <a class="basic-alignment right" href="{{page.next.url}}" title="next Post: {{page.next.title}}">{{page.next.title}} »</a> {% endif %} </p> diff --git a/_config.yml b/_config.yml index 9ab83617..fed545c5 100644 --- a/_config.yml +++ b/_config.yml @@ -8,6 +8,11 @@ subtitle: A blogging framework for hackers. author: Your Name 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 +date_format: "ordinal" + # RSS / Email (optional) subscription links (change if using something like Feedburner) subscribe_rss: /atom.xml subscribe_email: diff --git a/plugins/date.rb b/plugins/date.rb new file mode 100644 index 00000000..b3e9e35e --- /dev/null +++ b/plugins/date.rb @@ -0,0 +1,69 @@ +module Octopress + module Date + + # Returns a datetime if the input is a string + def datetime(date) + if date.class == String + date = Time.parse(date) + end + date + end + + # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007 + def ordinalize(date) + date = datetime(date) + "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}" + end + + # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc. + def ordinal(number) + if (11..13).include?(number.to_i % 100) + "#{number}<span>th</span>" + else + case number.to_i % 10 + when 1; "#{number}<span>st</span>" + when 2; "#{number}<span>nd</span>" + when 3; "#{number}<span>rd</span>" + else "#{number}<span>th</span>" + end + end + end + + end +end + + +module Jekyll + + class Post + include Octopress::Date + + attr_accessor :date_formatted + + # Convert this post into a Hash for use in Liquid templates. + # + # Returns <Hash> + def to_liquid + format = self.site.config['date_format'] + if format.nil? || format.empty? || format == "ordinal" + date_formatted = ordinalize(self.date) + else + date_formatted = self.date.strftime(format) + end + + self.data.deep_merge({ + "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), + "url" => self.url, + "date" => self.date, + # Monkey patch + "date_formatted" => date_formatted, + "id" => self.id, + "categories" => self.categories, + "next" => self.next, + "previous" => self.previous, + "tags" => self.tags, + "content" => self.content }) + end + + end +end
\ No newline at end of file diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index ef8c1fb2..997a740a 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -2,6 +2,7 @@ require './plugins/backtick_code_block' require './plugins/post_filters' require './plugins/raw' +require './plugins/date' require 'rubypants' module OctopressFilters @@ -33,6 +34,8 @@ end module OctopressLiquidFilters + include Octopress::Date + # Used on the blog index to split posts on the <!--more--> marker def excerpt(input) if input.index(/<!--\s*more\s*-->/i) @@ -96,33 +99,6 @@ module OctopressLiquidFilters input.titlecase end - # Returns a datetime if the input is a string - def datetime(date) - if date.class == String - date = Time.parse(date) - end - date - end - - # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007 - def ordinalize(date) - date = datetime(date) - "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}" - end - - # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc. - def ordinal(number) - if (11..13).include?(number.to_i % 100) - "#{number}<span>th</span>" - else - case number.to_i % 10 - when 1; "#{number}<span>st</span>" - when 2; "#{number}<span>nd</span>" - when 3; "#{number}<span>rd</span>" - else "#{number}<span>th</span>" - end - end - end end Liquid::Template.register_filter OctopressLiquidFilters |