From 5f860c66d300654934848aee1abe8e5c0d41836e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 11 Oct 2023 16:25:37 -0400 Subject: Added blog archive The path to blog posts is now "blog" instead of "says", btw. --- app/assets/stylesheets/main/entries.scss | 31 +++++++++++++++++++++++++++++++ app/controllers/admin/blogs_controller.rb | 2 +- app/controllers/blogs_controller.rb | 6 +++++- app/views/admin/blogs/_form.html.haml | 2 +- app/views/admin/blogs/index.html.haml | 2 +- app/views/blogs/index.atom.builder | 2 +- app/views/blogs/index.html.haml | 12 +++++++++--- app/views/blogs/summary.html.haml | 3 +++ config/routes.rb | 5 ++--- 9 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 app/views/blogs/summary.html.haml diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index b511333..b83082c 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss @@ -16,6 +16,7 @@ color: #59770e; border-bottom: 1px dotted #CCCCCC; padding-bottom: 3px; + font-family: "Trebuchet MS", sans-serif; a { text-decoration: none; @@ -186,3 +187,33 @@ } } } + +#blog-archive { + margin-left: 1em; + + h2, h3 { + font-family: "Trebuchet MS", sans-serif; + } +} + +.archive-link { + margin-left: 1em; + + a { + text-decoration: none; + font-weight: bold; + + &, &:visited { + color: #ee2c2c; + } + + &:hover { + text-decoration: underline; + color: #9ea1ad; + } + } + + small { + margin-left: 1.5em; + } +} diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index ea2c46c..c6d0168 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb @@ -13,7 +13,7 @@ class Admin::BlogsController < Admin::AdminController @blog = Blog.find(params[:id]) if @blog.published - redirect_to blog_url(@blog.slug) + redirect_to blog_post_url(@blog.slug) else render layout: "application" end diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index eda1bbb..c35a05d 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,7 +1,11 @@ class BlogsController < ApplicationController - def index + def summary @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) + end + + def index + @blogs = Blog.where(published: true).order(published_at: :desc) respond_to do |format| format.html diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 625c85e..01177c1 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml @@ -18,7 +18,7 @@ - unless f.object.new_record? #entry-preview-link.details-module - if f.object.published - = link_to "View post", blog_url(f.object.slug_was), target: "entry-preview" + = link_to "View post", blog_post_url(f.object.slug_was), target: "entry-preview" - else = link_to "Preview post", admin_blog_url(f.object.id), target: "entry-preview" .details-module diff --git a/app/views/admin/blogs/index.html.haml b/app/views/admin/blogs/index.html.haml index 9899176..c74fef5 100644 --- a/app/views/admin/blogs/index.html.haml +++ b/app/views/admin/blogs/index.html.haml @@ -10,5 +10,5 @@ %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P") %td %ul.admin-actions - %li= link_to "View", blog_url(blog.slug) + %li= link_to "View", blog_post_url(blog.slug) %li= link_to "Edit", edit_admin_blog_url(blog.id) diff --git a/app/views/blogs/index.atom.builder b/app/views/blogs/index.atom.builder index 72deba2..a05f29d 100644 --- a/app/views/blogs/index.atom.builder +++ b/app/views/blogs/index.atom.builder @@ -2,7 +2,7 @@ atom_feed do |feed| feed.title("Four Island") feed.updated(@blogs[0].published_at) if @blogs.length > 0 - @blogs.each do |blog| + @blogs.limit(10).each do |blog| feed.entry(blog, published: blog.published_at) do |entry| entry.title(blog.title) entry.content(markdown(blog.body), type: 'html') diff --git a/app/views/blogs/index.html.haml b/app/views/blogs/index.html.haml index e9639ca..75bf92f 100644 --- a/app/views/blogs/index.html.haml +++ b/app/views/blogs/index.html.haml @@ -1,3 +1,9 @@ -- @blogs.each do |blog| - = render blog, short: true -= will_paginate @blogs +#blog-archive + %h2 Blog Archive + .bubble.rounded + - @blogs.chunk {|blog| blog.published_at.strftime("%B %Y") }.each do |chunk| + %h3= chunk[0] + - chunk[1].each do |blog| + %p.archive-link + = link_to blog.title, blog + %small= blog.published_at.strftime("%-d %b %Y") diff --git a/app/views/blogs/summary.html.haml b/app/views/blogs/summary.html.haml new file mode 100644 index 0000000..e9639ca --- /dev/null +++ b/app/views/blogs/summary.html.haml @@ -0,0 +1,3 @@ +- @blogs.each do |blog| + = render blog, short: true += will_paginate @blogs diff --git a/config/routes.rb b/config/routes.rb index 514eb67..580cce4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,10 +22,9 @@ Rails.application.routes.draw do passwords: 'users/passwords' } - root "blogs#index" + root "blogs#summary" - get 'says', to: 'blogs#index' - get 'says/:slug', to: 'blogs#show', as: :blog + resources :blogs, only: [:index, :show], param: :slug, path: "blog" get 'thinks/:slug', to: 'streams#show', as: :stream -- cgit 1.4.1