From d233cb0dca7f6be981fd0783162398f10dfffeaf Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 10 Apr 2018 22:30:17 +0300 Subject: [PATCH] fix post ordering --- app/assets/stylesheets/hacker.sass | 4 ++-- app/models/post.rb | 10 +++++++--- app/views/blog/post.haml | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/hacker.sass b/app/assets/stylesheets/hacker.sass index 6def7c4..3b6aec2 100644 --- a/app/assets/stylesheets/hacker.sass +++ b/app/assets/stylesheets/hacker.sass @@ -11,7 +11,7 @@ $blockquote-border: $dove-grey !default body margin: 0 padding: 0 - background: $body-background url("../images/bkg.png") 0 0 + background: $body-background url("bkg.png") 0 0 color: $body-foreground font-size: 16px line-height: 1.5 @@ -136,7 +136,7 @@ dt ul li - list-style-image: url('../images/bullet.png') + list-style-image: url('bullet.png') blockquote diff --git a/app/models/post.rb b/app/models/post.rb index 2b80ae4..d283462 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -40,12 +40,16 @@ class Post end def self.posts return @@posts if @@posts - @@posts ={} + posts ={} Dir["#{self.blog_path}/_2*.haml"].reverse.each do |file| post = Post.new(file) - @@posts[post.slug] = post + posts[post.slug] = post end - @@posts + @@posts = posts.sort_by { |slug, post| post.sort_key }.reverse.to_h + end + + def sort_key + year*10000 + month*1000 + day end def self.blog_path diff --git a/app/views/blog/post.haml b/app/views/blog/post.haml index 86ed2a7..34a70f8 100644 --- a/app/views/blog/post.haml +++ b/app/views/blog/post.haml @@ -13,4 +13,4 @@ .center_col %h1= @post.title .center_col - = render( @post.template_name ) + = render( "posts/#{@post.template_name}" )