Fix titleize_slug so already capitalized words are not dropped
Previously `titleize` used `capitalize!` which has the side effect of
returning `nil` for anything already starting with a capital letter. This
commit changes it to just `capitalize`.
Example, before:
A file "2016-01-01-This-is-a-title-with-Capitals.markdown" would return "Is A
Title With" for `post.title`
Example, after:
A file "2016-01-01-This-is-a-title-with-Capitals.markdown" will return "This Is A
Title With Capitals" for `post.title`
Tests added for `titleize_slug` in test_utils.rb
Fix problem introduced in 67f842546e
References #4525
This commit is contained in:
parent
9dc273ca50
commit
e4aa45b03f
|
@ -20,7 +20,7 @@ module Jekyll
|
|||
|
||||
def titleize_slug(slug)
|
||||
slug.split("-").map! do |val|
|
||||
val.capitalize!
|
||||
val.capitalize
|
||||
end.join(" ")
|
||||
end
|
||||
|
||||
|
|
|
@ -206,6 +206,14 @@ class TestUtils < JekyllUnitTest
|
|||
end
|
||||
end
|
||||
|
||||
context "The \`Utils.titleize_slug\` method" do
|
||||
should "capitalize all words and not drop any words" do
|
||||
assert_equal "This Is A Long Title With Mixed Capitalization", Utils.titleize_slug("This-is-a-Long-title-with-Mixed-capitalization")
|
||||
assert_equal "This Is A Title With Just The Initial Word Capitalized", Utils.titleize_slug("This-is-a-title-with-just-the-initial-word-capitalized")
|
||||
assert_equal "This Is A Title With No Capitalization", Utils.titleize_slug("this-is-a-title-with-no-capitalization")
|
||||
end
|
||||
end
|
||||
|
||||
context "The \`Utils.add_permalink_suffix\` method" do
|
||||
should "handle built-in permalink styles" do
|
||||
assert_equal "/:basename/", Utils.add_permalink_suffix("/:basename", :pretty)
|
||||
|
|
Loading…
Reference in New Issue