diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 46dbfea1..d33abc56 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -32,7 +32,7 @@ module Jekyll begin self.data = YAML.load($1) rescue => e - puts "YAML Exception: #{e.message}" + puts "YAML Exception reading #{name}: #{e.message}" end end @@ -78,7 +78,7 @@ module Jekyll begin self.content = Liquid::Template.parse(self.content).render(payload, info) rescue => e - puts "Liquid Exception: #{e.message} in #{self.data["layout"]}" + puts "Liquid Exception: #{e.message} in #{self.name}" end self.transform diff --git a/lib/jekyll/migrators/wordpressdotcom.rb b/lib/jekyll/migrators/wordpressdotcom.rb index 53218e50..701c2af4 100644 --- a/lib/jekyll/migrators/wordpressdotcom.rb +++ b/lib/jekyll/migrators/wordpressdotcom.rb @@ -4,39 +4,67 @@ require 'rubygems' require 'hpricot' require 'fileutils' require 'yaml' +require 'time' module Jekyll # This importer takes a wordpress.xml file, which can be exported from your # wordpress.com blog (/wp-admin/export.php). module WordpressDotCom def self.process(filename = "wordpress.xml") - FileUtils.mkdir_p "_posts" - posts = 0 - + import_count = Hash.new(0) doc = Hpricot::XML(File.read(filename)) (doc/:channel/:item).each do |item| title = item.at(:title).inner_text.strip permalink_title = item.at('wp:post_name').inner_text - date = Time.parse(item.at(:pubDate).inner_text) + # Fallback to "prettified" title if post_name is empty (can happen) + if permalink_title == "" + permalink_title = title.downcase.split.join('-') + end + + date = Time.parse(item.at('wp:post_date').inner_text) + status = item.at('wp:status').inner_text + + if status == "publish" + published = true + else + published = false + end + + type = item.at('wp:post_type').inner_text tags = (item/:category).map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq + + metas = Hash.new + item.search("wp:postmeta").each do |meta| + key = meta.at('wp:meta_key').inner_text + value = meta.at('wp:meta_value').inner_text + metas[key] = value; + end + name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html" header = { - 'layout' => 'post', + 'layout' => type, 'title' => title, - 'tags' => tags + 'tags' => tags, + 'status' => status, + 'type' => type, + 'published' => published, + 'meta' => metas } - File.open("_posts/#{name}", "w") do |f| + FileUtils.mkdir_p "_#{type}s" + File.open("_#{type}s/#{name}", "w") do |f| f.puts header.to_yaml f.puts '---' f.puts item.at('content:encoded').inner_text end - posts += 1 + import_count[type] += 1 end - puts "Imported #{posts} posts" + import_count.each do |key, value| + puts "Imported #{value} #{key}s" + end end end end