From a84badc9cb7c53aa739bd9792adce2601948762f Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 26 Jul 2019 20:10:14 -0700 Subject: Allow for minute-grained date specifications --- lib/blog.rb | 7 ++++++- src/blog.html.erb | 2 +- src/index.html.erb | 2 +- src/post-template.html.erb | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/blog.rb b/lib/blog.rb index e4403a3..96e79dd 100644 --- a/lib/blog.rb +++ b/lib/blog.rb @@ -3,6 +3,7 @@ require 'date' def parse_post filename file_raw = File.read(src filename).force_encoding('UTF-8').split('---') post = YAML.load file_raw[0] + post['date'] = DateTime.parse(post['date']) post['content'] = file_raw[1].strip post['filename'] = filename post @@ -16,10 +17,14 @@ def posts Dir.new(src 'blog').children.map do |filename| post = parse_post "blog/#{filename}" end.sort do |a, b| - Date.parse(b['date']) <=> Date.parse(a['date']) + b['date'] <=> a['date'] end end +def format_date date + date.strftime '%B %-d, %Y' +end + def write_blog_files posts.each do |post| content = ERB.new(File.read(src 'post-template.html.erb')).result binding diff --git a/src/blog.html.erb b/src/blog.html.erb index d89494a..bd7b8aa 100644 --- a/src/blog.html.erb +++ b/src/blog.html.erb @@ -1,7 +1,7 @@ diff --git a/src/index.html.erb b/src/index.html.erb index 23f08bc..11715c1 100644 --- a/src/index.html.erb +++ b/src/index.html.erb @@ -9,7 +9,7 @@ diff --git a/src/post-template.html.erb b/src/post-template.html.erb index ece1545..033df48 100644 --- a/src/post-template.html.erb +++ b/src/post-template.html.erb @@ -1,2 +1,2 @@ -

<%= post['title'] %>

(<%= post['date'] %>) +

<%= post['title'] %>

(<%= format_date post['date'] %>) <%= post['content'] %> -- cgit v1.2.3