diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bf8e25d..f301ae8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,4 +19,12 @@ class ApplicationController < ActionController::Base s.id == id end end + + def find_post(site) + id = params[:post_id] || params[:id] + + site.posts.find do |p| + p.id == id + end + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 782d509..3a98367 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,4 +4,9 @@ class PostsController < ApplicationController def index @site = find_site end + + def show + @site = find_site + @post = find_post(@site) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 5ab63ca..9e7af91 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -72,6 +72,14 @@ class Post @post.basename != basename_from_front_matter end + def data + @post.data + end + + def content + @post.content + end + private def new_post diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 6c0942c..48492cc 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -5,4 +5,4 @@ - @site.posts.each do |post| %tr %td= link_to post.title, site_post_path(@site, post) - %td= post.date + %td= post.date.strftime('%F') diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml new file mode 100644 index 0000000..7df0997 --- /dev/null +++ b/app/views/posts/show.haml @@ -0,0 +1,24 @@ +.row + + %h1= @post.title + + .content + :markdown + #{@post.content} + + %table.table.table-condensed.table-striped + %tbody + - @post.data.each do |key, data| + %tr + %th= key + %td + - if data.respond_to? :each + - data.each do |d| + %span.badge.badge-success= d + - elsif data.respond_to? :content + :markdown + #{data.content} + - elsif data.respond_to? :strftime + = data.strftime('%F') + - else + = data