From 59447261a889b1b65f32e325894ef6fc2b9288c6 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 12 Aug 2019 21:06:13 -0700 Subject: Change post ids in pather --- lib/blog.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/blog.rb b/lib/blog.rb index 96e79dd..fe552e5 100644 --- a/lib/blog.rb +++ b/lib/blog.rb @@ -3,12 +3,22 @@ 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['raw_content'] = file_raw[1].strip post['filename'] = filename + post['id'] = "blog_#{basename_no_extension filename}" post end +def basename_no_extension filename + File.basename filename.sub(/\.[\w.]*$/, '') +end + +def compile_post post + post['content'] = ERB.new(post['raw_content']).result binding +end + def generate_blog_post post ERB.new(File.read(src 'post-template.html.erb')).result binding end @@ -27,6 +37,7 @@ end def write_blog_files posts.each do |post| + compile_post post content = ERB.new(File.read(src 'post-template.html.erb')).result binding write_templated content, post['filename'], head_title: post['title'], h1_title: 'Blog.' end -- cgit v1.2.3