Skip to content

Instantly share code, notes, and snippets.

@bradpauly
Created January 2, 2013 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradpauly/4437195 to your computer and use it in GitHub Desktop.
Save bradpauly/4437195 to your computer and use it in GitHub Desktop.
#!/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