From 49c39f43a1c19958ab414692736987b2ae1c8b37 Mon Sep 17 00:00:00 2001 From: eugenebolshakov Date: Sun, 10 May 2009 15:29:05 +0400 Subject: [PATCH] the index page should always have index.html permalink no matter what --- features/permalinks.feature | 9 +++++++++ lib/jekyll/page.rb | 15 +++++++++++---- test/test_page.rb | 10 +++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/features/permalinks.feature b/features/permalinks.feature index 9bd7c848..8e50ee72 100644 --- a/features/permalinks.feature +++ b/features/permalinks.feature @@ -23,6 +23,15 @@ Feature: Fancy permalinks Then the _site directory should exist And I should see "Totally wordpress." in "_site/2009/03/27/pretty-permalink-schema/index.html" + 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 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" + Scenario: Use custom permalink schema with prefix Given I have a _posts directory And I have the following post: diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 8cd0b2c8..b3a624f3 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -4,7 +4,7 @@ module Jekyll include Convertible attr_accessor :site - attr_accessor :name, :ext + attr_accessor :name, :ext, :basename attr_accessor :data, :content, :output # Initialize a new Page. @@ -24,7 +24,6 @@ module Jekyll self.process(name) self.read_yaml(File.join(base, dir), name) - #self.transform end # The generated directory into which the page will be placed @@ -46,7 +45,7 @@ module Jekyll end def template - if self.site.permalink_style == :pretty + if self.site.permalink_style == :pretty && !index? "/:name/" else "/:name.html" @@ -60,7 +59,7 @@ module Jekyll def url return permalink if permalink - @url ||= template.gsub(':name', name.split('.')[0..-2].first) + @url ||= template.gsub(':name', basename) end # Extract information from the page filename @@ -69,6 +68,7 @@ module Jekyll # Returns nothing def process(name) self.ext = File.extname(name) + self.basename = name.split('.')[0..-2].first end # Add any necessary layouts to this post @@ -102,6 +102,13 @@ module Jekyll f.write(self.output) end end + + private + + def index? + basename == 'index' + end + end end diff --git a/test/test_page.rb b/test/test_page.rb index 331e868b..1715d916 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -24,11 +24,19 @@ class TestPage < Test::Unit::TestCase end context "with pretty url style" do - should "return dir correctly" do + setup do @site.permalink_style = :pretty + end + + should "return dir correctly" do @page = setup_page('contacts.html') assert_equal '/contacts/', @page.dir end + + should "return dir correctly for index page" do + @page = setup_page('index.html') + assert_equal '/', @page.dir + end end context "with any other url style" do