bugfix for permalinks

Signed-off-by: Nick Quaranto <nick@quaran.to>
This commit is contained in:
Jeffry Degrande 2009-06-29 08:40:31 -03:00 committed by Nick Quaranto
parent f1c8e388e4
commit 176c047ff1
4 changed files with 38 additions and 2 deletions

View File

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

View File

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

23
test/source/sitemap.xml Normal file
View File

@ -0,0 +1,23 @@
---
layout: nil
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://example.com</loc>
<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
{% for post in site.posts %}
<url>
<loc>http://example.com/{{ post.url }}/</loc>
<lastmod>{{ site.time }}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.2</priority>
</url>
{% endfor %}
</urlset>

View File

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