From 365f57e8b3cdae73d63e7e44fba7b41cd4cc8e26 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 28 Jun 2011 02:05:51 -0700 Subject: [PATCH] Added meta tag import goodness. This for instance allows you to preserve all your hard-worked on WP SEO keywords, images, alternative images and other yummy-ness. Replaced PubDate with wp:post_date, this is better than PubDate since some of the posts you import could be a draft (in this case the pubDate is invalid and contains a non-sensical value). Added wp:status so we now know whether the post is published, draft or in the trash. Added wp:post_type so we differentiate between posts and image or other post types --- lib/jekyll/migrators/wordpressdotcom.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/migrators/wordpressdotcom.rb b/lib/jekyll/migrators/wordpressdotcom.rb index 53218e50..62187a77 100644 --- a/lib/jekyll/migrators/wordpressdotcom.rb +++ b/lib/jekyll/migrators/wordpressdotcom.rb @@ -4,6 +4,7 @@ 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 @@ -18,13 +19,26 @@ module Jekyll (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) + date = Time.parse(item.at('wp:post_date').inner_text) + status = item.at('wp:status').inner_text + 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', 'title' => title, - 'tags' => tags + 'tags' => tags, + 'status' => status, + 'type' => type, + 'meta' => metas } File.open("_posts/#{name}", "w") do |f|