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

Convert slashes in titles to dashes when migrating from WordPress #684

Merged
merged 1 commit into from
Jan 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jekyll.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Gem::Specification.new do |s|
s.add_development_dependency('RedCloth', "~> 4.2") s.add_development_dependency('RedCloth', "~> 4.2")
s.add_development_dependency('rdiscount', "~> 1.6") s.add_development_dependency('rdiscount', "~> 1.6")
s.add_development_dependency('redcarpet', "~> 1.9") s.add_development_dependency('redcarpet', "~> 1.9")
s.add_development_dependency('sequel', "~> 3.42")
s.add_development_dependency('htmlentities', "~> 4.3")
s.add_development_dependency('hpricot', "~> 0.8")


# = MANIFEST = # = MANIFEST =
s.files = %w[ s.files = %w[
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/migrators/wordpress.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def self.clean_entities( text )
text.gsub!(">", ">") text.gsub!(">", ">")
text.gsub!(""", '"') text.gsub!(""", '"')
text.gsub!("'", "'") text.gsub!("'", "'")
text.gsub!("/", "/")
text text
end end


Expand Down
6 changes: 5 additions & 1 deletion lib/jekyll/migrators/wordpressdotcom.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.process(filename = "wordpress.xml")
permalink_title = item.at('wp:post_name').inner_text permalink_title = item.at('wp:post_name').inner_text
# Fallback to "prettified" title if post_name is empty (can happen) # Fallback to "prettified" title if post_name is empty (can happen)
if permalink_title == "" if permalink_title == ""
permalink_title = title.downcase.split.join('-') permalink_title = sluggify(title)
end end


date = Time.parse(item.at('wp:post_date').inner_text) date = Time.parse(item.at('wp:post_date').inner_text)
Expand Down Expand Up @@ -66,5 +66,9 @@ def self.process(filename = "wordpress.xml")
puts "Imported #{value} #{key}s" puts "Imported #{value} #{key}s"
end end
end end

def self.sluggify(title)
title.downcase.split.join('-').gsub('/','-')
end
end end
end end
10 changes: 10 additions & 0 deletions test/test_wordpress_migrator.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'helper'
require 'jekyll/migrators/wordpress'
require 'htmlentities'

class TestWordpressMigrator < Test::Unit::TestCase
should "clean slashes from slugs" do
test_title = "blogs part 1/2"
assert_equal("blogs-part-1-2", Jekyll::WordPress.sluggify(test_title))
end
end
9 changes: 9 additions & 0 deletions test/test_wordpressdotcom_migrator.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'helper'
require 'jekyll/migrators/wordpressdotcom'

class TestWordpressDotComMigrator < Test::Unit::TestCase
should "clean slashes from slugs" do
test_title = "blogs part 1/2"
assert_equal("blogs-part-1-2", Jekyll::WordpressDotCom.sluggify(test_title))
end
end