From 176c047ff16493205f9ed17df36f989598443570 Mon Sep 17 00:00:00 2001 From: Jeffry Degrande Date: Mon, 29 Jun 2009 08:40:31 -0300 Subject: [PATCH] bugfix for permalinks Signed-off-by: Nick Quaranto --- features/permalinks.feature | 2 ++ lib/jekyll/page.rb | 4 ++-- test/source/sitemap.xml | 23 +++++++++++++++++++++++ test/test_page.rb | 11 +++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/source/sitemap.xml diff --git a/features/permalinks.feature b/features/permalinks.feature index 8e50ee72..050e75c3 100644 --- a/features/permalinks.feature +++ b/features/permalinks.feature @@ -26,11 +26,13 @@ Feature: Fancy permalinks Scenario: Use pretty permalink schema for pages Given I have an "index.html" page that contains "Totally index" And I have an "awesome.html" page that contains "Totally awesome" + And I have an "sitemap.xml" page that contains "Totally uhm, sitemap" And I have a configuration file with "permalink" set to "pretty" When I run jekyll Then the _site directory should exist And I should see "Totally index" in "_site/index.html" And I should see "Totally awesome" in "_site/awesome/index.html" + And I should see "Totally uhm, sitemap" in "_site/sitemap.xml" Scenario: Use custom permalink schema with prefix Given I have a _posts directory diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 537df3d4..20463903 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -57,7 +57,7 @@ module Jekyll def url return permalink if permalink - @url ||= template.gsub(':name', basename) + @url ||= (ext == '.html') ? template.gsub(':name', basename) : "/#{name}" end # Extract information from the page filename @@ -91,7 +91,7 @@ module Jekyll # The url needs to be unescaped in order to preserve the correct filename path = File.join(dest, CGI.unescape(self.url)) - if self.url[/\.html$/].nil? + if self.ext == '.html' && self.url[/\.html$/].nil? FileUtils.mkdir_p(path) path = File.join(path, "index.html") end diff --git a/test/source/sitemap.xml b/test/source/sitemap.xml new file mode 100644 index 00000000..96b38a14 --- /dev/null +++ b/test/source/sitemap.xml @@ -0,0 +1,23 @@ +--- +layout: nil +--- + + + + + http://example.com + {{ site.time | date_to_xmlschema }} + daily + 1.0 + + + {% for post in site.posts %} + + http://example.com/{{ post.url }}/ + {{ site.time }} + monthly + 0.2 + + {% endfor %} + \ No newline at end of file diff --git a/test/test_page.rb b/test/test_page.rb index 1715d916..6fbb003d 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -81,6 +81,17 @@ class TestPage < Test::Unit::TestCase assert File.exists?(File.join(dest_dir, 'contacts', 'index.html')) end + should "write properly with extension different from html" do + page = setup_page("sitemap.xml") + page.site.permalink_style = :pretty + do_render(page) + page.write(dest_dir) + + assert_equal("/sitemap.xml", page.url) + assert_nil(page.url[/\.html$/]) + assert File.directory?(dest_dir) + assert File.exists?(File.join(dest_dir,'sitemap.xml')) + end end end