Created
August 19, 2012 13:11
-
-
Save sbusso/3394740 to your computer and use it in GitHub Desktop.
Webby to Jekyll migrator
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
require 'yaml' | |
require 'fileutils' | |
module Jekyll | |
module Webby | |
def self.process(webby_data_dir) | |
raise ArgumentError, "webby dir #{webby_data_dir} not found" unless File.directory?(webby_data_dir) | |
posts = 0 | |
Dir["#{webby_data_dir}/**/*.txt"].each do |f| | |
next unless File.exists?(f) | |
file_content = File.read(f) | |
meta = YAML.load(file_content) | |
body = file_content[/\n---\n(.*)/m, 1] | |
meta['layout'] = 'post' | |
meta.delete('filter') | |
meta.delete('blog_post') | |
formatted_date = meta['created_at'].strftime('%Y-%m-%d-') | |
meta.delete('created_at') | |
file_name = File.dirname(f) + '/'+ formatted_date + File.basename(f).sub('.txt', '.textile') | |
File.open(file_name, "w") do |f| | |
f.puts meta.to_yaml | |
f.puts "---\n" | |
f.puts "\n{% include JB/setup %}\n\n" | |
f.puts body | |
end | |
posts += 1 | |
end | |
puts "Created #{posts} posts!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment