From 8379958d957d81065ff6961adca6b427538a2e35 Mon Sep 17 00:00:00 2001 From: Urban Hafner Date: Wed, 3 Jun 2009 08:48:16 +0300 Subject: [PATCH] Order posts by slug name if the date is the same --- features/site_data.feature | 4 +++- lib/jekyll/post.rb | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/features/site_data.feature b/features/site_data.feature index 18786254..aada7213 100644 --- a/features/site_data.feature +++ b/features/site_data.feature @@ -65,10 +65,12 @@ Feature: Site data And I have an "index.html" page that contains "{% for post in site.posts %}{{ post.title }}:{{ post.previous.title}},{{ post.next.title}} {% endfor %}" And I have the following posts: | title | date | content | + | first | 2/26/2009 | first | | A | 3/26/2009 | A | | B | 3/26/2009 | B | | C | 3/26/2009 | C | + | last | 4/26/2009 | last | When I run jekyll Then the _site directory should exist - And I should see "C:B, B:A,C A:,B" in "_site/index.html" + And I should see "last:C, C:B,last B:A,C A:first,B first:,A" in "_site/index.html" \ No newline at end of file diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index d164fb5e..4171c735 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -70,11 +70,15 @@ module Jekyll end end - # Spaceship is based on Post#date + # Spaceship is based on Post#date, slug # # Returns -1, 0, 1 def <=>(other) - self.date <=> other.date + cmp = self.date <=> other.date + if 0 == cmp + cmp = self.slug <=> other.slug + end + return cmp end # Extract information from the post filename