Skip to content
This repository

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

Merged
merged 1 commit into from over 1 year ago

3 participants

Matt Rogers Parker Moore Aleksey V. Zapparov
Matt Rogers
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

Matt Rogers 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
Matt Rogers
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:

Parker Moore
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!)

Parker Moore
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 :-)

Aleksey V. Zapparov

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...

Parker Moore parkr merged commit 8fb4e8f into from January 18, 2013
Parker Moore parkr closed this January 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 04, 2012
Matt Rogers 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
This page is out of date. Refresh to see the latest.
3  jekyll.gemspec
@@ -38,6 +38,9 @@ Gem::Specification.new do |s|
38 38
   s.add_development_dependency('RedCloth', "~> 4.2")
39 39
   s.add_development_dependency('rdiscount', "~> 1.6")
40 40
   s.add_development_dependency('redcarpet', "~> 1.9")
  41
+  s.add_development_dependency('sequel', "~> 3.42")
  42
+  s.add_development_dependency('htmlentities', "~> 4.3")
  43
+  s.add_development_dependency('hpricot', "~> 0.8")
41 44
   
42 45
   # = MANIFEST =
43 46
   s.files = %w[
1  lib/jekyll/migrators/wordpress.rb
@@ -276,6 +276,7 @@ def self.clean_entities( text )
276 276
       text.gsub!(">", ">")
277 277
       text.gsub!(""", '"')
278 278
       text.gsub!("'", "'")
  279
+      text.gsub!("/", "/")
279 280
       text
280 281
     end
281 282
 
6  lib/jekyll/migrators/wordpressdotcom.rb
@@ -19,7 +19,7 @@ def self.process(filename = "wordpress.xml")
19 19
         permalink_title = item.at('wp:post_name').inner_text
20 20
         # Fallback to "prettified" title if post_name is empty (can happen)
21 21
         if permalink_title == ""
22  
-          permalink_title = title.downcase.split.join('-')
  22
+          permalink_title = sluggify(title)
23 23
         end
24 24
 
25 25
         date = Time.parse(item.at('wp:post_date').inner_text)
@@ -66,5 +66,9 @@ def self.process(filename = "wordpress.xml")
66 66
         puts "Imported #{value} #{key}s"
67 67
       end
68 68
     end
  69
+
  70
+    def self.sluggify(title)
  71
+      title.downcase.split.join('-').gsub('/','-')
  72
+    end
69 73
   end
70 74
 end
10  test/test_wordpress_migrator.rb
... ...
@@ -0,0 +1,10 @@
  1
+require 'helper'
  2
+require 'jekyll/migrators/wordpress'
  3
+require 'htmlentities'
  4
+
  5
+class TestWordpressMigrator < Test::Unit::TestCase
  6
+  should "clean slashes from slugs" do
  7
+    test_title = "blogs part 1/2"
  8
+    assert_equal("blogs-part-1-2", Jekyll::WordPress.sluggify(test_title))
  9
+  end
  10
+end
9  test/test_wordpressdotcom_migrator.rb
... ...
@@ -0,0 +1,9 @@
  1
+require 'helper'
  2
+require 'jekyll/migrators/wordpressdotcom'
  3
+
  4
+class TestWordpressDotComMigrator < Test::Unit::TestCase
  5
+  should "clean slashes from slugs" do
  6
+    test_title = "blogs part 1/2"
  7
+    assert_equal("blogs-part-1-2", Jekyll::WordpressDotCom.sluggify(test_title))
  8
+  end
  9
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.