Changing to the template permalink system, only test_post passing so far
This commit is contained in:
parent
73fa7dcad4
commit
288d5045d2
|
@ -109,13 +109,34 @@ module Jekyll
|
|||
self.data && self.data['permalink']
|
||||
end
|
||||
|
||||
def template
|
||||
case self.site.permalink_style
|
||||
when :pretty
|
||||
"/:year/:month/:day/:title"
|
||||
when :none
|
||||
"/:title.html"
|
||||
when :date
|
||||
"/:year/:month/:day/:title.html"
|
||||
else
|
||||
self.site.permalink_style
|
||||
end
|
||||
end
|
||||
|
||||
# The generated relative url of this post
|
||||
# e.g. /2008/11/05/my-awesome-post.html
|
||||
#
|
||||
# Returns <String>
|
||||
def url
|
||||
ext = self.site.permalink_style == :pretty ? '' : '.html'
|
||||
permalink || self.id + ext
|
||||
return permalink if permalink
|
||||
|
||||
{
|
||||
"year" => date.strftime("%Y"),
|
||||
"month" => date.strftime("%m"),
|
||||
"day" => date.strftime("%d"),
|
||||
"title" => slug
|
||||
}.inject(template) { |result, token|
|
||||
result.gsub(/:#{token.first}/, token.last)
|
||||
}
|
||||
end
|
||||
|
||||
# The UID for this post (useful in feeds)
|
||||
|
|
|
@ -49,8 +49,7 @@ class TestPost < Test::Unit::TestCase
|
|||
assert_equal "/2008/10/19/foo-bar.html", @post.url
|
||||
end
|
||||
|
||||
|
||||
should "respect permalink" do
|
||||
should "respect permalink in yaml front matter" do
|
||||
file = "2008-12-03-permalinked-post.textile"
|
||||
@post.process(file)
|
||||
@post.read_yaml(@source, file)
|
||||
|
@ -60,30 +59,60 @@ class TestPost < Test::Unit::TestCase
|
|||
assert_equal "my_category/permalinked-post", @post.url
|
||||
end
|
||||
|
||||
context "with permalink style of none" do
|
||||
|
||||
context "with site wide permalink" do
|
||||
setup do
|
||||
@post.site.permalink_style = :none
|
||||
@post.categories = []
|
||||
end
|
||||
|
||||
context "with unspecified (date) style" do
|
||||
setup do
|
||||
@post.process(@fake_file)
|
||||
end
|
||||
|
||||
should "process the url correctly" do
|
||||
assert_equal "/:year/:month/:day/:title.html", @post.template
|
||||
assert_equal "/2008/10/19/foo-bar.html", @post.url
|
||||
end
|
||||
end
|
||||
|
||||
context "with none style" do
|
||||
setup do
|
||||
@post.site.permalink_style = :none
|
||||
@post.process(@fake_file)
|
||||
end
|
||||
|
||||
should "process the url correctly" do
|
||||
assert_equal "/:title.html", @post.template
|
||||
assert_equal "/foo-bar.html", @post.url
|
||||
end
|
||||
end
|
||||
|
||||
context "with permalink style of pretty" do
|
||||
context "with pretty style" do
|
||||
setup do
|
||||
@post.site.permalink_style = :pretty
|
||||
@post.categories = []
|
||||
@post.process(@fake_file)
|
||||
end
|
||||
|
||||
should "process the url correctly" do
|
||||
assert_equal "/:year/:month/:day/:title", @post.template
|
||||
assert_equal "/2008/10/19/foo-bar", @post.url
|
||||
end
|
||||
end
|
||||
|
||||
context "with prefix style and no extension" do
|
||||
setup do
|
||||
@post.site.permalink_style = "/prefix/:title"
|
||||
@post.process(@fake_file)
|
||||
end
|
||||
|
||||
should "process the url correctly" do
|
||||
assert_equal "/prefix/:title", @post.template
|
||||
assert_equal "/prefix/foo-bar", @post.url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "read yaml front-matter" do
|
||||
@post.read_yaml(@source, @real_file)
|
||||
|
||||
|
|
Loading…
Reference in New Issue