blob: e4403a320b0d6f67b586deb73d225a54bd36f100 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
|