m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-15 14:29:30 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-15 14:29:30 +0100
commit05868777b47a60cba919fa6bd5e90737979de6f7 (patch)
treeec4118042034ad45934e9c5a86c3030f287e54ad /lib
parent9ced764fc28d8d655da178badf8ab94211676700 (diff)
Clean up post compilation
* All posts are compiled before writing them * Templated posts don't end up with .erb suffix
Diffstat (limited to 'lib')
-rw-r--r--lib/blog.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/blog.rb b/lib/blog.rb
index 656f815..7500aa8 100644
--- a/lib/blog.rb
+++ b/lib/blog.rb
@@ -6,7 +6,7 @@ def parse_post filename
post['date'] = DateTime.parse(post['date'])
post['raw_content'] = file_raw[1].strip
- post['filename'] = filename
+ post['html_filename'] = filename.sub /\.erb$/, ''
post['id'] = "blog_#{basename_no_extension filename}"
post
end
@@ -19,12 +19,20 @@ def compile_post post
post['content'] = ERB.new(post['raw_content']).result binding
end
+def compile_posts posts
+ posts.each do |post|
+ compile_post post
+ end
+end
+
def generate_blog_post post
ERB.new(File.read(src 'post-template.html.erb')).result binding
end
+@posts = nil
+
def posts
- Dir.new(src 'blog').children.map do |filename|
+ @posts ||= Dir.new(src 'blog').children.map do |filename|
post = parse_post "blog/#{filename}"
end.sort do |a, b|
b['date'] <=> a['date']
@@ -37,9 +45,8 @@ 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.'
+ write_templated content, post['html_filename'], head_title: post['title'], h1_title: 'Blog.'
end
end