sort posts by reverse chronology
This commit is contained in:
parent
7c3cfad2df
commit
b2d2d09f95
|
@ -1,6 +1,8 @@
|
||||||
module AutoBlog
|
module AutoBlog
|
||||||
|
|
||||||
class Post
|
class Post
|
||||||
|
include Comparable
|
||||||
|
|
||||||
MATCHER = /^(\d+-\d+-\d+)-(.*)\.([^.]+)$/
|
MATCHER = /^(\d+-\d+-\d+)-(.*)\.([^.]+)$/
|
||||||
|
|
||||||
def self.valid?(name)
|
def self.valid?(name)
|
||||||
|
@ -20,6 +22,10 @@ module AutoBlog
|
||||||
self.transform
|
self.transform
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def <=>(other)
|
||||||
|
self.date <=> other.date
|
||||||
|
end
|
||||||
|
|
||||||
def process(name)
|
def process(name)
|
||||||
m, date, slug, ext = *name.match(MATCHER)
|
m, date, slug, ext = *name.match(MATCHER)
|
||||||
self.date = Time.parse(date)
|
self.date = Time.parse(date)
|
||||||
|
|
|
@ -70,7 +70,7 @@ module AutoBlog
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_payload
|
def site_payload
|
||||||
{"site" => {"time" => Time.now, "posts" => self.posts}}
|
{"site" => {"time" => Time.now, "posts" => self.posts.sort.reverse}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue