Merge commit 'ad29ef'
This commit is contained in:
commit
f5c727fadb
|
@ -55,13 +55,27 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
# The generated directory into which the post will be placed
|
# The generated directory into which the post will be placed
|
||||||
# upon generation. e.g. "/2008/11/05/"
|
# upon generation. This is derived from the permalink or, if
|
||||||
|
# permalink is absent, set to the default date
|
||||||
|
# e.g. "/2008/11/05/"
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns <String>
|
||||||
def dir
|
def dir
|
||||||
self.date.strftime("/%Y/%m/%d/")
|
permalink ?
|
||||||
|
permalink.to_s.split("/")[0..-2].join("/") :
|
||||||
|
date.strftime("/%Y/%m/%d/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The full path and filename of the post.
|
||||||
|
# Defined in the YAML of the post body
|
||||||
|
# (Optional)
|
||||||
|
#
|
||||||
|
# Returns <String>
|
||||||
|
def permalink
|
||||||
|
self.data && self.data['permalink']
|
||||||
|
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
|
||||||
#
|
#
|
||||||
|
@ -111,7 +125,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def write(dest)
|
def write(dest)
|
||||||
FileUtils.mkdir_p(File.join(dest, self.dir))
|
FileUtils.mkdir_p(File.join(dest, dir))
|
||||||
|
|
||||||
path = File.join(dest, self.url)
|
path = File.join(dest, self.url)
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
title: Post with Permalink
|
||||||
|
permalink: my_category/permalinked-post
|
||||||
|
---
|
||||||
|
|
||||||
|
h1. {{ page.title }}
|
||||||
|
|
||||||
|
|
||||||
|
<p>Best <strong>post</strong> ever</p>
|
|
@ -26,6 +26,22 @@ class TestPost < Test::Unit::TestCase
|
||||||
assert_equal "/2008/10/19/foo-bar.html", p.url
|
assert_equal "/2008/10/19/foo-bar.html", p.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_permalink
|
||||||
|
p = Post.allocate
|
||||||
|
p.process("2008-12-03-permalinked-post.textile")
|
||||||
|
p.read_yaml(File.join(File.dirname(__FILE__), *%w[source posts]), "2008-12-03-permalinked-post.textile")
|
||||||
|
|
||||||
|
assert_equal "my_category/permalinked-post", p.permalink
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_dir_respects_permalink
|
||||||
|
p = Post.allocate
|
||||||
|
p.process("2008-12-03-permalinked-post.textile")
|
||||||
|
p.read_yaml(File.join(File.dirname(__FILE__), *%w[source posts]), "2008-12-03-permalinked-post.textile")
|
||||||
|
|
||||||
|
assert_equal "my_category", p.dir
|
||||||
|
end
|
||||||
|
|
||||||
def test_read_yaml
|
def test_read_yaml
|
||||||
p = Post.allocate
|
p = Post.allocate
|
||||||
p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-10-18-foo-bar.textile")
|
p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-10-18-foo-bar.textile")
|
||||||
|
|
Loading…
Reference in New Issue