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']
|
self.data && self.data['permalink']
|
||||||
end
|
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
|
# The generated relative url of this post
|
||||||
# e.g. /2008/11/05/my-awesome-post.html
|
# e.g. /2008/11/05/my-awesome-post.html
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns <String>
|
||||||
def url
|
def url
|
||||||
ext = self.site.permalink_style == :pretty ? '' : '.html'
|
return permalink if permalink
|
||||||
permalink || self.id + ext
|
|
||||||
|
{
|
||||||
|
"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
|
end
|
||||||
|
|
||||||
# The UID for this post (useful in feeds)
|
# 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
|
assert_equal "/2008/10/19/foo-bar.html", @post.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "respect permalink in yaml front matter" do
|
||||||
should "respect permalink" do
|
|
||||||
file = "2008-12-03-permalinked-post.textile"
|
file = "2008-12-03-permalinked-post.textile"
|
||||||
@post.process(file)
|
@post.process(file)
|
||||||
@post.read_yaml(@source, file)
|
@post.read_yaml(@source, file)
|
||||||
|
@ -60,27 +59,57 @@ class TestPost < Test::Unit::TestCase
|
||||||
assert_equal "my_category/permalinked-post", @post.url
|
assert_equal "my_category/permalinked-post", @post.url
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with permalink style of none" do
|
|
||||||
|
context "with site wide permalink" do
|
||||||
setup do
|
setup do
|
||||||
@post.site.permalink_style = :none
|
|
||||||
@post.categories = []
|
@post.categories = []
|
||||||
@post.process(@fake_file)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "process the url correctly" do
|
context "with unspecified (date) style" do
|
||||||
assert_equal "/foo-bar.html", @post.url
|
setup do
|
||||||
end
|
@post.process(@fake_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with permalink style of pretty" do
|
should "process the url correctly" do
|
||||||
setup do
|
assert_equal "/:year/:month/:day/:title.html", @post.template
|
||||||
@post.site.permalink_style = :pretty
|
assert_equal "/2008/10/19/foo-bar.html", @post.url
|
||||||
@post.categories = []
|
end
|
||||||
@post.process(@fake_file)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "process the url correctly" do
|
context "with none style" do
|
||||||
assert_equal "/2008/10/19/foo-bar", @post.url
|
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 pretty style" do
|
||||||
|
setup do
|
||||||
|
@post.site.permalink_style = :pretty
|
||||||
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue