From 73212a27079e6b9eaa45ddecb6f6d44f0e1b5cc2 Mon Sep 17 00:00:00 2001 From: Tom Bell Date: Sun, 27 May 2012 05:33:03 +0100 Subject: [PATCH 1/2] Turn the title into a slug This allows the title to be correctly used as a filename. Fixes #523 --- lib/jekyll/migrators/wordpressdotcom.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/wordpressdotcom.rb b/lib/jekyll/migrators/wordpressdotcom.rb index 701c2af44f2..74b60210660 100644 --- a/lib/jekyll/migrators/wordpressdotcom.rb +++ b/lib/jekyll/migrators/wordpressdotcom.rb @@ -19,7 +19,7 @@ def self.process(filename = "wordpress.xml") permalink_title = item.at('wp:post_name').inner_text # Fallback to "prettified" title if post_name is empty (can happen) if permalink_title == "" - permalink_title = title.downcase.split.join('-') + permalink_title = title.gsub(/[^[:alnum:]]+/, '-').downcase end date = Time.parse(item.at('wp:post_date').inner_text) From 988a7a86657c83e3b462be719e18f64c2011e454 Mon Sep 17 00:00:00 2001 From: Tom Bell Date: Wed, 30 May 2012 20:56:05 -0400 Subject: [PATCH 2/2] Add test case for wordpressdotcom migrator * Add hpricot to dev dependencies so we can use the migrator * Add example wordpress.xml file for testing with * Add `fixtures_dir` method to helper file * Add test to see if 2 posts and 1 page are imported --- jekyll.gemspec | 1 + lib/jekyll/migrators/wordpressdotcom.rb | 2 + test/fixtures/wordpress.xml | 149 ++++++++++++++++++++++++ test/helper.rb | 4 + test/migrators/test_wordpressdotcom.rb | 18 +++ 5 files changed, 174 insertions(+) create mode 100644 test/fixtures/wordpress.xml create mode 100644 test/migrators/test_wordpressdotcom.rb diff --git a/jekyll.gemspec b/jekyll.gemspec index 88655609526..361a3a7ebf4 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |s| s.add_development_dependency('RedCloth', "~> 4.2") s.add_development_dependency('rdiscount', "~> 1.6") s.add_development_dependency('redcarpet', "~> 1.9") + s.add_development_dependency('hpricot', "~> 0.8.6") # = MANIFEST = s.files = %w[ diff --git a/lib/jekyll/migrators/wordpressdotcom.rb b/lib/jekyll/migrators/wordpressdotcom.rb index 74b60210660..243dedf488f 100644 --- a/lib/jekyll/migrators/wordpressdotcom.rb +++ b/lib/jekyll/migrators/wordpressdotcom.rb @@ -65,6 +65,8 @@ def self.process(filename = "wordpress.xml") import_count.each do |key, value| puts "Imported #{value} #{key}s" end + + import_count end end end diff --git a/test/fixtures/wordpress.xml b/test/fixtures/wordpress.xml new file mode 100644 index 00000000000..2b29a85f995 --- /dev/null +++ b/test/fixtures/wordpress.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + Test + http://tombtest.wordpress.com + A fine WordPress.com site + Wed, 30 May 2012 23:38:48 +0000 + en + 1.2 + http://wordpress.com/ + http://tombtest.wordpress.com + + 1402643tombelltomb@tomb.io + + 1uncategorized + + http://wordpress.com/ + + + http://s2.wp.com/i/buttonw-com.png + Test + http://tombtest.wordpress.com + + + diff --git a/test/helper.rb b/test/helper.rb index c6a8a763280..ec1cf92d916 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -28,6 +28,10 @@ def source_dir(*subdirs) File.join(File.dirname(__FILE__), 'source', *subdirs) end + def fixtures_dir(*subdirs) + File.join(File.dirname(__FILE__), 'fixtures', *subdirs) + end + def clear_dest FileUtils.rm_rf(dest_dir) end diff --git a/test/migrators/test_wordpressdotcom.rb b/test/migrators/test_wordpressdotcom.rb new file mode 100644 index 00000000000..e40eafafbdc --- /dev/null +++ b/test/migrators/test_wordpressdotcom.rb @@ -0,0 +1,18 @@ +require 'helper' +require 'jekyll/migrators/wordpressdotcom' + +class TestWordpressDotCom < Test::Unit::TestCase + context 'migrating from wordpress.com' do + setup do + @wordpressxml = File.join(fixtures_dir, 'wordpress.xml') + end + + should 'import post with a slash in the title from wordpress.xml' do + stub(FileUtils).mkdir_p(anything) + stub(File).open(anything, anything) + imported = Jekyll::WordpressDotCom.process(@wordpressxml) + assert_equal 1, imported['page'] + assert_equal 2, imported['post'] + end + end +end