Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'kramdown'
require 'date'
source = ARGV[0]
destination = ARGV[1]
Dir.chdir(source) do |dir|
@posts = []
Dir.glob("20*.md") do |md_file|
post = File.read(md_file)
html_file = File.basename(md_file, '.md') + '.html'
File.open(File.join([destination, html_file]), 'w+') do |f|
# 2012-01-02-title-of-my-post.md
date = md_file[0,10]
@title = md_file[11..-4].gsub('-', ' ')
@posts << { :title => @title, :slug => html_file, :date => date }
@content = Kramdown::Document.new(post).to_html
f.write ERB.new(File.read(File.join([source, 'layout.html.erb']))).result(binding)
end
end
File.open(File.join([destination, 'index.html']), 'w+') do |f|
f.write ERB.new(File.read(File.join([source, 'archive.html.erb']))).result(binding)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment