Skip to content

Commit

Permalink
sort posts by reverse chronology
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Oct 22, 2008
1 parent 7c3cfad commit b2d2d09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/autoblog/post.rb
@@ -1,6 +1,8 @@
module AutoBlog

class Post
include Comparable

MATCHER = /^(\d+-\d+-\d+)-(.*)\.([^.]+)$/

def self.valid?(name)
Expand All @@ -20,6 +22,10 @@ def initialize(base, name)
self.transform
end

def <=>(other)
self.date <=> other.date
end

def process(name)
m, date, slug, ext = *name.match(MATCHER)
self.date = Time.parse(date)
Expand Down
2 changes: 1 addition & 1 deletion lib/autoblog/site.rb
Expand Up @@ -70,7 +70,7 @@ def transform_pages(dir = '')
end

def site_payload
{"site" => {"time" => Time.now, "posts" => self.posts}}
{"site" => {"time" => Time.now, "posts" => self.posts.sort.reverse}}
end
end

Expand Down

0 comments on commit b2d2d09

Please sign in to comment.