Created
January 2, 2013 19:32
-
-
Save bradpauly/4437195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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