From b6678d4e4310ead39310b688fb6b2dae8fc189a3 Mon Sep 17 00:00:00 2001 From: Matt Hall Date: Thu, 2 Sep 2010 13:36:31 +0100 Subject: [PATCH] Added Wordpress.com migrator --- lib/jekyll/migrators/wordpress.com.rb | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/jekyll/migrators/wordpress.com.rb diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb new file mode 100644 index 00000000000..5be1b42d214 --- /dev/null +++ b/lib/jekyll/migrators/wordpress.com.rb @@ -0,0 +1,38 @@ +require 'rubygems' +require 'hpricot' +require 'fileutils' + +# This importer takes a wordpress.xml file, +# which can be exported from your +# wordpress.com blog (/wp-admin/export.php) + +module Jekyll + module WordpressDotCom + def self.process(filename = "wordpress.xml") + FileUtils.mkdir_p "_posts" + posts = 0 + + doc = Hpricot::XML(File.read(filename)) + + (doc/:channel/:item).each do |item| + title = item.at(:title).inner_text + name = "#{Date.parse((doc/:channel/:item).first.at(:pubDate).inner_text).to_s("%Y-%m-%d")}-#{title.downcase.gsub('[^a-z0-9]', '-')}.html" + + File.open("_posts/#{name}", "w") do |f| + f.puts <<-HEADER +--- +layout: post +title: #{title} +--- + +HEADER + f.puts item.at('content:encoded').inner_text + end + + posts += 1 + end + + "Imported #{posts} posts" + end + end +end \ No newline at end of file