Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and add tag support for the wordpress.com migrator #274

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions lib/jekyll/migrators/wordpress.com.rb
@@ -1,12 +1,15 @@
# coding: utf-8

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)
require 'yaml'

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"
Expand All @@ -15,24 +18,28 @@ def self.process(filename = "wordpress.xml")
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"

title = item.at(:title).inner_text.strip
permalink_title = item.at('wp:post_name').inner_text
date = Time.parse(item.at(:pubDate).inner_text)
tags = (item/:category).map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
header = {
'layout' => 'post',
'title' => title,
'tags' => tags
}

File.open("_posts/#{name}", "w") do |f|
f.puts <<-HEADER
---
layout: post
title: #{title}
---

HEADER
f.puts header.to_yaml
f.puts '---'
f.puts item.at('content:encoded').inner_text
end

posts += 1
end

"Imported #{posts} posts"
puts "Imported #{posts} posts"
end
end

end