Skip to content

Instantly share code, notes, and snippets.

@sbusso
Created August 19, 2012 13:11
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 sbusso/3394740 to your computer and use it in GitHub Desktop.
Save sbusso/3394740 to your computer and use it in GitHub Desktop.
Webby to Jekyll migrator
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