From a3b86375c946299c9216412e10c5bcf5234c7fcd Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 28 Jun 2019 19:12:42 +0200 Subject: Initial commit --- lib/blog.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/blog.rb (limited to 'lib/blog.rb') diff --git a/lib/blog.rb b/lib/blog.rb new file mode 100644 index 0000000..e4403a3 --- /dev/null +++ b/lib/blog.rb @@ -0,0 +1,33 @@ +require 'date' + +def parse_post filename + file_raw = File.read(src filename).force_encoding('UTF-8').split('---') + post = YAML.load file_raw[0] + post['content'] = file_raw[1].strip + post['filename'] = filename + post +end + +def generate_blog_post post + ERB.new(File.read(src 'post-template.html.erb')).result binding +end + +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']) + end +end + +def write_blog_files + posts.each do |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 +end + +def write_blog_archive + content = ERB.new(File.read(src 'blog.html.erb')).result + write_templated content, 'blog.html', title: 'Blog.' +end -- cgit v1.2.3