From cc83501489c41c96b35ea26b55f7df31faf65dee Mon Sep 17 00:00:00 2001 From: Daniel Hilgarth Date: Sun, 3 Mar 2013 14:56:18 +0100 Subject: [PATCH 1/3] Fix broken post_url with posts with a time in their YAML front matter. --- lib/jekyll/post.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index b8d0ad55..c2d70199 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -79,12 +79,15 @@ module Jekyll # Compares Post objects. First compares the Post date. If the dates are # equal, it compares the Post slugs. + # This comparison is used to create internal links using post_url. + # Post filenames are without a time, but the date property in the YAML + # front matter can be with time, so we compare only the date here. # # other - The other Post we are comparing to. # # Returns -1, 0, 1 def <=>(other) - cmp = self.date <=> other.date + cmp = self.date.to_date <=> other.date.to_date if 0 == cmp cmp = self.slug <=> other.slug end From ce8e1afba6574c1e2de651798c02be4e308c7dd6 Mon Sep 17 00:00:00 2001 From: Daniel Hilgarth Date: Sun, 3 Mar 2013 15:12:21 +0100 Subject: [PATCH 2/3] Add support for Ruby < 1.9 --- lib/jekyll/post.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index c2d70199..ab912d82 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -87,7 +87,9 @@ module Jekyll # # Returns -1, 0, 1 def <=>(other) - cmp = self.date.to_date <=> other.date.to_date + cmp = self.date.year <=> other.date.year + cmp = self.date.month <=> other.date.month if cmp == 0 + cmp = self.date.day <=> other.date.day if cmp == 0 if 0 == cmp cmp = self.slug <=> other.slug end From 87f6f8c971e1930fe37b82ffd76c19d57c4d485e Mon Sep 17 00:00:00 2001 From: Daniel Hilgarth Date: Sun, 3 Mar 2013 15:36:16 +0100 Subject: [PATCH 3/3] Fix invalid ordering of posts published on the same day and move post_url specific comparison of posts where it belongs: Into post_url --- lib/jekyll/post.rb | 7 +------ lib/jekyll/tags/post_url.rb | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index ab912d82..b8d0ad55 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -79,17 +79,12 @@ module Jekyll # Compares Post objects. First compares the Post date. If the dates are # equal, it compares the Post slugs. - # This comparison is used to create internal links using post_url. - # Post filenames are without a time, but the date property in the YAML - # front matter can be with time, so we compare only the date here. # # other - The other Post we are comparing to. # # Returns -1, 0, 1 def <=>(other) - cmp = self.date.year <=> other.date.year - cmp = self.date.month <=> other.date.month if cmp == 0 - cmp = self.date.day <=> other.date.day if cmp == 0 + cmp = self.date <=> other.date if 0 == cmp cmp = self.slug <=> other.slug end diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index ff4a29b8..008c12a2 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -23,7 +23,7 @@ module Jekyll site = context.registers[:site] site.posts.each do |p| - if p == @post + if p.slug == @post.slug and p.date.year == @post.date.year and p.date.month == @post.date.month and p.date.day == @post.date.day return p.url end end