From 0022f3e1ce95b538315fa29fd654eb3a2d923b5d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 13 Oct 2023 14:57:41 -0400 Subject: Fixed display of draft blog posts --- app/models/blog.rb | 8 ++++++++ app/views/admin/blogs/show.html.haml | 2 +- app/views/blogs/_blog.html.haml | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/blog.rb b/app/models/blog.rb index b677e2b..e640466 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -32,6 +32,14 @@ class Blog < ApplicationRecord slug end + def visible_date + if published + published_at + else + updated_at + end + end + private def set_draft_title if self.title.blank? and not self.published diff --git a/app/views/admin/blogs/show.html.haml b/app/views/admin/blogs/show.html.haml index b9acd5d..f50f69d 100644 --- a/app/views/admin/blogs/show.html.haml +++ b/app/views/admin/blogs/show.html.haml @@ -1,5 +1,5 @@ - title "Previewing #{@blog.title}" -= render partial: "blogs/blog", object: @blog += render "blogs/blog", blog: @blog, short: false %footer#blog-footer This draft was last updated on = succeed "." do diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index c607e63..5467683 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -1,8 +1,8 @@ %article#blog-post %header - .post-calendar{ class: "post-date-#{(blog.published_at.year - 2007) % 4 + 1}" } - %span.post-month= blog.published_at.strftime("%^b") - %span.post-day= blog.published_at.day + .post-calendar{ class: "post-date-#{(blog.visible_date.year - 2007) % 4 + 1}" } + %span.post-month= blog.visible_date.strftime("%^b") + %span.post-day= blog.visible_date.day .blog-title %h2= link_to_unless_current blog.title, blog .post-author Hatkirby @@ -18,4 +18,4 @@ %cite.bubble %strong Hatkirby on - = blog.published_at.strftime("%B #{blog.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") + = blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") -- cgit 1.4.1