From 9e0eb75170e56ec9fcc68bab6c7a639ad3a23f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Wed, 15 Dec 2010 15:44:01 -0300 Subject: [PATCH 1/4] updated/fixed wordpress.com migration script --- lib/jekyll/migrators/wordpress.com.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb index 5be1b42d..96e0d917 100644 --- a/lib/jekyll/migrators/wordpress.com.rb +++ b/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) @@ -15,8 +19,13 @@ module Jekyll 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 @@ -32,7 +41,7 @@ HEADER posts += 1 end - "Imported #{posts} posts" + puts "Imported #{posts} posts" end end -end \ No newline at end of file +end From f68bbcbe8d22beb577aaae5b109aca835ac637ad Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 27 Jan 2011 02:12:42 -0800 Subject: [PATCH 2/4] The Wordpress.com migrator now works and gathers categories as tags. --- lib/jekyll/migrators/wordpress.com.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb index 5be1b42d..dd7d77f6 100644 --- a/lib/jekyll/migrators/wordpress.com.rb +++ b/lib/jekyll/migrators/wordpress.com.rb @@ -1,6 +1,7 @@ require 'rubygems' require 'hpricot' require 'fileutils' +require 'yaml' # This importer takes a wordpress.xml file, # which can be exported from your @@ -16,16 +17,20 @@ module Jekyll (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" - + 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")}-#{title.downcase.gsub(/\W+/, '-')}.html" + header = { + 'layout' => 'post', + 'title' => title, + 'tags' => tags + } + + File.mkdir("_posts") unless File.directory?("_posts") File.open("_posts/#{name}", "w") do |f| - f.puts <<-HEADER ---- -layout: post -title: #{title} ---- - -HEADER + f.puts header.to_yaml + f.puts '---' + f.puts f.puts item.at('content:encoded').inner_text end From c70dac3ceec0b667f6eda31589160fd83bb9b2d4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 27 Jan 2011 13:12:08 +0100 Subject: [PATCH 3/4] Take permalink name directly from worpress export file. --- lib/jekyll/migrators/wordpress.com.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb index 2e02fd23..90e5fe45 100644 --- a/lib/jekyll/migrators/wordpress.com.rb +++ b/lib/jekyll/migrators/wordpress.com.rb @@ -19,9 +19,10 @@ 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) tags = (item/:category).map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq - name = "#{date.strftime("%Y-%m-%d")}-#{title.downcase.tr('áéíóúàèìòùâêîôûãẽĩõũñäëïöüç','aeiouaeiouaeiouaeiounaeiouc').gsub(/\W+/, '-')}.html" + name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html" header = { 'layout' => 'post', 'title' => title, From 034b06431e4a108d419e10fd814c46433dee7d9e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 27 Jan 2011 13:13:12 +0100 Subject: [PATCH 4/4] Remove double directory creation. --- lib/jekyll/migrators/wordpress.com.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb index 90e5fe45..069d6118 100644 --- a/lib/jekyll/migrators/wordpress.com.rb +++ b/lib/jekyll/migrators/wordpress.com.rb @@ -29,7 +29,6 @@ module Jekyll 'tags' => tags } - File.mkdir("_posts") unless File.directory?("_posts") File.open("_posts/#{name}", "w") do |f| f.puts header.to_yaml f.puts '---'