Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

@mattr-
Owner

When a post has a title that contains a slash, such as 'This is my cool
blog post part 1/2', convert the slash to a dash so that the post
filename is created correctly.

Fixes issue #680

@mattr- mattr- Convert slashes in titles to dashes when migrating from WordPress
When a post has a title that contains a slash, such as 'This is my cool
blog post part 1/2', convert the slash to a dash so that the post
filename is created correctly.

Fixes issue #680
8fb4e8f
@mattr-
Owner

I don't like that I had to add all those dependencies to the gemspec, but they were needed to make the tests for the migrator run. :cry:

@parkr
Owner

Adding in those dependencies were the only way to run the tests?! It doesn't look like any of that code at all should be required. Weird.

(Also please rebase on current master!)

@parkr
Owner

We're going to move all the migrators to a sub-gem, jekyll-migrators (or something like that) soon. I'm weary about adding those gemspec dependencies - we can do this (and add tests) later for the migrators :-)

@ixti

Why not simply denote in the gemspec that dependencies are for migrators only. Merge pull request and then upon gem separation cleanup gemspec. You'll have to do this anyway, but at least when you'll find time to split gems you'll have less time trying merge such changes on...

@parkr parkr merged commit 8fb4e8f into jekyll:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 5, 2012
  1. @mattr-

    Convert slashes in titles to dashes when migrating from WordPress

    mattr- authored
    When a post has a title that contains a slash, such as 'This is my cool
    blog post part 1/2', convert the slash to a dash so that the post
    filename is created correctly.
    
    Fixes issue #680
This page is out of date. Refresh to see the latest.
View
3  jekyll.gemspec
@@ -38,6 +38,9 @@ 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('sequel', "~> 3.42")
+ s.add_development_dependency('htmlentities', "~> 4.3")
+ s.add_development_dependency('hpricot', "~> 0.8")
# = MANIFEST =
s.files = %w[
View
1  lib/jekyll/migrators/wordpress.rb
@@ -276,6 +276,7 @@ def self.clean_entities( text )
text.gsub!(">", ">")
text.gsub!(""", '"')
text.gsub!("'", "'")
+ text.gsub!("/", "/")
text
end
View
6 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 = sluggify(title)
end
date = Time.parse(item.at('wp:post_date').inner_text)
@@ -66,5 +66,9 @@ def self.process(filename = "wordpress.xml")
puts "Imported #{value} #{key}s"
end
end
+
+ def self.sluggify(title)
+ title.downcase.split.join('-').gsub('/','-')
+ end
end
end
View
10 test/test_wordpress_migrator.rb
@@ -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
View
9 test/test_wordpressdotcom_migrator.rb
@@ -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
Something went wrong with that request. Please try again.