From 4090500c5a9220e49eb0e0c77fcd843d5feaef08 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Mon, 9 Apr 2012 02:47:20 +0300 Subject: [PATCH 1/3] Added path in url. Page#dir was returning the wrong dir ('/') for pages in directories. --- lib/jekyll/page.rb | 9 +++-- test/source/contacts/bar.html | 5 +++ test/source/contacts/index.html | 5 +++ test/test_page.rb | 65 ++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 test/source/contacts/bar.html create mode 100644 test/source/contacts/index.html diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 82b82048..faf340b8 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -46,9 +46,9 @@ module Jekyll # Returns the template String. def template if self.site.permalink_style == :pretty && !index? && html? - "/:basename/" + "/:path/:basename/" else - "/:basename:output_ext" + "/:path/:basename:output_ext" end end @@ -62,6 +62,7 @@ module Jekyll permalink else { + "path" => @dir, "basename" => self.basename, "output_ext" => self.output_ext, }.inject(template) { |result, token| @@ -105,7 +106,7 @@ module Jekyll # Returns the Hash representation of this Page. def to_liquid self.data.deep_merge({ - "url" => File.join(@dir, self.url), + "url" => self.url, "content" => self.content }) end @@ -117,7 +118,7 @@ module Jekyll def destination(dest) # The url needs to be unescaped in order to preserve the correct # filename. - path = File.join(dest, @dir, CGI.unescape(self.url)) + path = File.join(dest, CGI.unescape(self.url)) path = File.join(path, "index.html") if self.url =~ /\/$/ path end diff --git a/test/source/contacts/bar.html b/test/source/contacts/bar.html new file mode 100644 index 00000000..1615afe2 --- /dev/null +++ b/test/source/contacts/bar.html @@ -0,0 +1,5 @@ +--- +title: Contact Information +--- + +Contact Information diff --git a/test/source/contacts/index.html b/test/source/contacts/index.html new file mode 100644 index 00000000..1615afe2 --- /dev/null +++ b/test/source/contacts/index.html @@ -0,0 +1,5 @@ +--- +title: Contact Information +--- + +Contact Information diff --git a/test/test_page.rb b/test/test_page.rb index 61278997..6d4bef2a 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -1,8 +1,10 @@ require 'helper' class TestPage < Test::Unit::TestCase - def setup_page(file) - @page = Page.new(@site, source_dir, '', file) + def setup_page(*args) + dir, file = args + dir, file = ['', dir] if file.nil? + @page = Page.new(@site, source_dir, dir, file) end def do_render(page) @@ -23,6 +25,18 @@ class TestPage < Test::Unit::TestCase assert_equal "/contacts.html", @page.url end + context "in a directory hierarchy" do + should "create url based on filename" do + @page = setup_page('/contacts', 'bar.html') + assert_equal "/contacts/bar.html", @page.url + end + + should "create index url based on filename" do + @page = setup_page('/contacts', 'index.html') + assert_equal "/contacts/index.html", @page.url + end + end + should "deal properly with extensions" do @page = setup_page('deal.with.dots.html') assert_equal ".html", @page.ext @@ -47,6 +61,23 @@ class TestPage < Test::Unit::TestCase @page = setup_page('index.html') assert_equal '/', @page.dir end + + context "in a directory hierarchy" do + should "create url based on filename" do + @page = setup_page('/contacts', 'index.html') + assert_equal "/contacts/index.html", @page.url + end + + should "return dir correctly" do + @page = setup_page('/contacts', 'bar.html') + assert_equal '/contacts/bar/', @page.dir + end + + should "return dir correctly for index page" do + @page = setup_page('/contacts', 'index.html') + assert_equal '/contacts', @page.dir + end + end end context "with any other url style" do @@ -111,6 +142,36 @@ class TestPage < Test::Unit::TestCase assert File.directory?(dest_dir) assert File.exists?(File.join(dest_dir, '.htaccess')) end + + context "in a directory hierarchy" do + should "write properly the index" do + page = setup_page('/contacts', 'index.html') + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exists?(File.join(dest_dir, 'contacts', 'index.html')) + end + + should "write properly" do + page = setup_page('/contacts', 'bar.html') + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exists?(File.join(dest_dir, 'contacts', 'bar.html')) + end + + should "write properly without html extension" do + page = setup_page('/contacts', 'bar.html') + page.site.permalink_style = :pretty + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exists?(File.join(dest_dir, 'contacts', 'bar', 'index.html')) + end + end end end From 441eddf1caf9905aa1a909a229c2045832da000b Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Thu, 28 Feb 2013 03:49:39 +0200 Subject: [PATCH 2/3] Fix pretty url style paths. Ignore the basename if the page is an index page, preserve it if it's just an html page and use the full path in every other case. --- lib/jekyll/page.rb | 10 ++++++++-- test/test_page.rb | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index faf340b8..b20bee22 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -45,8 +45,14 @@ module Jekyll # # Returns the template String. def template - if self.site.permalink_style == :pretty && !index? && html? - "/:path/:basename/" + if self.site.permalink_style == :pretty + if index? && html? + "/:path/" + elsif html? + "/:path/:basename/" + else + "/:path/:basename:output_ext" + end else "/:path/:basename:output_ext" end diff --git a/test/test_page.rb b/test/test_page.rb index 6d4bef2a..8d13cda7 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -64,8 +64,13 @@ class TestPage < Test::Unit::TestCase context "in a directory hierarchy" do should "create url based on filename" do + @page = setup_page('/contacts', 'bar.html') + assert_equal "/contacts/bar/", @page.url + end + + should "create index url based on filename" do @page = setup_page('/contacts', 'index.html') - assert_equal "/contacts/index.html", @page.url + assert_equal "/contacts/", @page.url end should "return dir correctly" do @@ -75,7 +80,7 @@ class TestPage < Test::Unit::TestCase should "return dir correctly for index page" do @page = setup_page('/contacts', 'index.html') - assert_equal '/contacts', @page.dir + assert_equal '/contacts/', @page.dir end end end From f79662719befef6f9b2e3b5638b974015f9e780f Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Sat, 9 Mar 2013 15:07:22 +0200 Subject: [PATCH 3/3] Fix indentation. --- lib/jekyll/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index b20bee22..ccdbda86 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -48,7 +48,7 @@ module Jekyll if self.site.permalink_style == :pretty if index? && html? "/:path/" - elsif html? + elsif html? "/:path/:basename/" else "/:path/:basename:output_ext"