Order posts by slug name if the date is the same

This commit is contained in:
Urban Hafner 2009-06-03 08:48:16 +03:00
parent d8d7ae3f0e
commit 8379958d95
2 changed files with 9 additions and 3 deletions

View File

@ -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"

View File

@ -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