Merge pull request #998 from dhcole/master

Use post's directory path when matching for the post_url tag
This commit is contained in:
Parker Moore 2013-05-05 05:16:39 -07:00
commit 290ba131e2
5 changed files with 37 additions and 6 deletions

View File

@ -6,13 +6,15 @@ module Jekyll
attr_accessor :date, :slug
def initialize(name)
who, cares, date, slug = *name.match(MATCHER)
@slug = slug
all, path, date, slug = *name.sub(/^\//, "").match(MATCHER)
@slug = path ? path + slug : slug
@date = Time.parse(date)
end
def ==(other)
slug == other.slug &&
path = other.name.split("/")[0...-1].join("/")
otherslug = path != "" ? path + '/' + other.slug : other.slug
slug == otherslug &&
date.year == other.date.year &&
date.month == other.date.month &&
date.day == other.date.day

View File

@ -0,0 +1,8 @@
---
layout: default
title: Nested
---
url: {{ page.url }}
date: {{ page.date }}
id: {{ page.id }}

View File

@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end
should "ensure post count is as expected" do
assert_equal 32, @site.posts.size
assert_equal 33, @site.posts.size
end
should "insert site.posts into the index" do

View File

@ -162,7 +162,7 @@ class TestSite < Test::Unit::TestCase
@site.read_posts('')
posts = Dir[source_dir('_posts', '*')]
posts.delete_if { |post| File.directory?(post) }
assert_equal posts.size - 1, @site.posts.size
assert_equal posts.size, @site.posts.size
end
should "deploy payload" do
@ -173,7 +173,7 @@ class TestSite < Test::Unit::TestCase
posts.delete_if { |post| File.directory?(post) }
categories = %w(bar baz category foo z_category publish_test win).sort
assert_equal posts.size, @site.posts.size
assert_equal posts.size + 1, @site.posts.size
assert_equal categories, @site.categories.keys.sort
assert_equal 4, @site.categories['foo'].size
end

View File

@ -204,6 +204,27 @@ CONTENT
end
end
context "simple page with nested post linking" do
setup do
content = <<CONTENT
---
title: Post linking
---
{% post_url es/2008-11-21-nested %}
CONTENT
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
end
should "not cause an error" do
assert_no_match /markdown\-html\-error/, @result
end
should "have the url to the \"complex\" post from 2008-11-21" do
assert_match %r{/2008/11/21/nested/}, @result
end
end
context "gist tag" do
context "simple" do
setup do