summaryrefslogtreecommitdiff
path: root/build-files/build_posts.rb
blob: eead269fba87e896f53481936946a9876d48de84 (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
34
35
36
37
38
require 'erb'
require 'kramdown'

def render(partial_path)
  ERB.new(File.read(partial_path)).result(binding)
end

def content
	output = Array.new
	Dir.foreach("./content/posts") do |post_filename|
	if post_filename.include?("md")
	 	output.push(Kramdown::Document.new(File.read("./content/posts/#{post_filename}")).to_html)
		end
	end
	return output
end 

def filename
	file = Array.new
	Dir.foreach("./content/posts") do |post_filename|
		if post_filename.include?("md")
			file.push("#{post_filename}.html")
		end
	end
	return file
end

i = 0
while (i < content.length)
	@content = content[i]
	template = ERB.new(File.read('recipe-template.html.erb'))
	puts template.result(binding)
	file = filename[i]
	File.open(file, 'w') do |f|
		f.write(template.result)
		end
	i += 1
end