Merge pull request #536 from fotos/fix_page_dir

Added path in url.
This commit is contained in:
Parker Moore 2013-03-09 17:07:16 -08:00
commit 725b127f9b
4 changed files with 90 additions and 7 deletions

View File

@ -56,10 +56,16 @@ module Jekyll
# #
# Returns the template String. # Returns the template String.
def template def template
if self.site.permalink_style == :pretty && !index? && html? if self.site.permalink_style == :pretty
"/:basename/" if index? && html?
"/:path/"
elsif html?
"/:path/:basename/"
else
"/:path/:basename:output_ext"
end
else else
"/:basename:output_ext" "/:path/:basename:output_ext"
end end
end end
@ -73,6 +79,7 @@ module Jekyll
permalink permalink
else else
{ {
"path" => @dir,
"basename" => self.basename, "basename" => self.basename,
"output_ext" => self.output_ext, "output_ext" => self.output_ext,
}.inject(template) { |result, token| }.inject(template) { |result, token|
@ -116,7 +123,7 @@ module Jekyll
# Returns the Hash representation of this Page. # Returns the Hash representation of this Page.
def to_liquid def to_liquid
self.data.deep_merge({ self.data.deep_merge({
"url" => File.join(@dir, self.url), "url" => self.url,
"content" => self.content }) "content" => self.content })
end end
@ -128,7 +135,7 @@ module Jekyll
def destination(dest) def destination(dest)
# The url needs to be unescaped in order to preserve the correct # The url needs to be unescaped in order to preserve the correct
# filename. # 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 = File.join(path, "index.html") if self.url =~ /\/$/
path path
end end

View File

@ -0,0 +1,5 @@
---
title: Contact Information
---
Contact Information

View File

@ -0,0 +1,5 @@
---
title: Contact Information
---
Contact Information

View File

@ -1,8 +1,10 @@
require 'helper' require 'helper'
class TestPage < Test::Unit::TestCase class TestPage < Test::Unit::TestCase
def setup_page(file) def setup_page(*args)
@page = Page.new(@site, source_dir, '', file) dir, file = args
dir, file = ['', dir] if file.nil?
@page = Page.new(@site, source_dir, dir, file)
end end
def do_render(page) def do_render(page)
@ -23,6 +25,18 @@ class TestPage < Test::Unit::TestCase
assert_equal "/contacts.html", @page.url assert_equal "/contacts.html", @page.url
end 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 should "deal properly with extensions" do
@page = setup_page('deal.with.dots.html') @page = setup_page('deal.with.dots.html')
assert_equal ".html", @page.ext assert_equal ".html", @page.ext
@ -47,6 +61,28 @@ class TestPage < Test::Unit::TestCase
@page = setup_page('index.html') @page = setup_page('index.html')
assert_equal '/', @page.dir assert_equal '/', @page.dir
end end
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/", @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 end
context "with any other url style" do context "with any other url style" do
@ -131,6 +167,36 @@ class TestPage < Test::Unit::TestCase
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exists?(File.join(dest_dir, '.htaccess')) assert File.exists?(File.join(dest_dir, '.htaccess'))
end 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
end end