about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/assets/stylesheets/main/entries.scss24
-rw-r--r--app/controllers/blogs_controller.rb3
-rw-r--r--app/models/blog.rb8
-rw-r--r--app/views/blogs/show.html.haml6
4 files changed, 40 insertions, 1 deletions
diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index 3b7215c..fd03de9 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss
@@ -426,3 +426,27 @@
426 text-decoration: none; 426 text-decoration: none;
427 } 427 }
428} 428}
429
430.back-post, .next-post {
431 margin-left: 1em;
432 margin-bottom: 1em;
433 margin-right: 1em;
434
435 a, a:visited {
436 color: #555d66;
437 text-decoration: none;
438 font-size: .75em;
439 }
440
441 a:hover {
442 text-decoration: underline;
443 }
444}
445
446.back-post {
447 float: left;
448}
449
450.next-post {
451 float: right;
452}
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 2f9df49..033d6bb 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -24,6 +24,9 @@ class BlogsController < ApplicationController
24 raise ActiveRecord::RecordNotFound unless @blog 24 raise ActiveRecord::RecordNotFound unless @blog
25 raise ActiveRecord::RecordNotFound unless @blog.published 25 raise ActiveRecord::RecordNotFound unless @blog.published
26 26
27 @prev = @blog.prev
28 @next = @blog.next
29
27 body = Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(@blog.body) 30 body = Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(@blog.body)
28 31
29 set_meta_tags(og: { 32 set_meta_tags(og: {
diff --git a/app/models/blog.rb b/app/models/blog.rb index 03643bf..8599bcd 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -48,6 +48,14 @@ class Blog < ApplicationRecord
48 end 48 end
49 end 49 end
50 50
51 def prev
52 Blog.where(published: true).where("published_at < ?", published_at).order(published_at: :desc).first
53 end
54
55 def next
56 Blog.where(published: true).where("published_at > ?", published_at).order(published_at: :asc).first
57 end
58
51 private 59 private
52 def set_draft_title 60 def set_draft_title
53 if self.title.blank? and not self.published 61 if self.title.blank? and not self.published
diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index 0c549ac..7558257 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml
@@ -1,4 +1,8 @@
1- title @blog.title 1- title @blog.title
2.breadcrumb= link_to "← Back to home page", root_path 2- unless @prev.nil?
3 .back-post= link_to "← #{@prev.title}", @prev
4- unless @next.nil?
5 .next-post= link_to "#{@next.title} →", @next
6.clear
3= render @blog, short: false 7= render @blog, short: false
4= show_comments(@blog) 8= show_comments(@blog)