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

Updated/Fixed Wordpress.com importer #252

Closed
wants to merge 1 commit 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
17 changes: 13 additions & 4 deletions lib/jekyll/migrators/wordpress.com.rb
@@ -1,7 +1,11 @@
# coding: utf-8

require 'rubygems'
require 'hpricot'
require 'fileutils'

require 'date'

# This importer takes a wordpress.xml file,
# which can be exported from your
# wordpress.com blog (/wp-admin/export.php)
Expand All @@ -15,8 +19,13 @@ 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
date = item.at(:pubDate).inner_text

ftitle = title.downcase.tr('áéíóúàèìòùâêîôûãẽĩõũñäëïöüç','aeiouaeiouaeiouaeiounaeiouc').gsub(/[^a-z0-9]/, '-')
fdate = DateTime.strptime(date, '%a, %d %b %G %T')

name = "#{fdate.strftime('%Y-%m-%d')}-#{ftitle}.html"

File.open("_posts/#{name}", "w") do |f|
f.puts <<-HEADER
Expand All @@ -32,7 +41,7 @@ def self.process(filename = "wordpress.xml")
posts += 1
end

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