From a5e51cfdbeaad33534f2370f9e30db1bf594d2a0 Mon Sep 17 00:00:00 2001 From: Chris Frederick Date: Mon, 1 Sep 2014 13:25:38 +0900 Subject: [PATCH] Properly handle titles with trailing punctuation --- lib/jekyll/document.rb | 2 +- test/source/_slides/example-slide-4.html | 15 +++++++++++++++ test/test_document.rb | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/source/_slides/example-slide-4.html diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 036e25e7..0b4b72ec 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -53,7 +53,7 @@ module Jekyll # sequence of spaces and non-alphanumeric characters replaced with a # hyphen. def slug(name) - name.downcase.gsub(/[\W\s]+/, '-') + name.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') end # The extension name of the document. diff --git a/test/source/_slides/example-slide-4.html b/test/source/_slides/example-slide-4.html new file mode 100644 index 00000000..6cec4eae --- /dev/null +++ b/test/source/_slides/example-slide-4.html @@ -0,0 +1,15 @@ +--- + title: So what is Jekyll, exactly? + layout: slide +--- + +Jekyll is a simple, blog-aware, static site generator. It takes a template +directory containing raw text files in various formats, runs it through +[Markdown](http://daringfireball.net/projects/markdown/) (or +[Textile](http://redcloth.org/textile)) and +[Liquid](http://wiki.shopify.com/Liquid) +converters, and spits out a complete, ready-to-publish static website suitable +for serving with your favorite web server. Jekyll also happens to be the engine +behind [GitHub Pages](http://pages.github.com), which means you can use Jekyll +to host your project’s page, blog, or website from GitHub’s servers **for +free**. diff --git a/test/test_document.rb b/test/test_document.rb index 2899325e..1ffc5431 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -213,18 +213,18 @@ class TestDocument < Test::Unit::TestCase "collections" => { "slides" => { "output" => true, - "permalink" => "/slides/test/:title" + "permalink" => "/slides/:title" } }, "source" => source_dir, "destination" => dest_dir })) @site.process - @document = @site.collections["slides"].docs[0] + @document = @site.collections["slides"].docs[3] end should "produce the right URL" do - assert_equal "/slides/test/example-slide", @document.url + assert_equal "/slides/so-what-is-jekyll-exactly", @document.url end end