Skip to content

Commit

Permalink
allow date to be specified in the front matter and override the value…
Browse files Browse the repository at this point in the history
… from the file name, fixes jekyll#62 and jekyll#38
  • Loading branch information
krisb committed Jan 10, 2010
1 parent 6b74454 commit a1550b3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/jekyll/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def initialize(site, source, dir, name)
self.process(name)
self.read_yaml(@base, name)

#If we've added a date and time to the yaml, use that instead of the filename date
#Means we'll sort correctly.
if self.data.has_key?('date')
# ensure Time via to_s and reparse
self.date = Time.parse(self.data["date"].to_s)
end

if self.data.has_key?('published') && self.data['published'] == false
self.published = false
else
Expand Down
5 changes: 5 additions & 0 deletions test/source/_posts/2010-01-09-date-override.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
date: 2010-01-10
---

Post with a front matter date
5 changes: 5 additions & 0 deletions test/source/_posts/2010-01-09-time-override.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
date: 2010-01-10 13:07:09
---

Post with a front matter time
2 changes: 1 addition & 1 deletion test/test_generated_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end

should "ensure post count is as expected" do
assert_equal 18, @site.posts.size
assert_equal 20, @site.posts.size
end

should "insert site.posts into the index" do
Expand Down
10 changes: 10 additions & 0 deletions test/test_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ def do_render(post)
assert_equal false, post.published
end

should "recognize date in yaml" do
post = setup_post("2010-01-09-date-override.textile")
assert_equal "/2010/01/10/date-override.html", post.url
end

should "recognize time in yaml" do
post = setup_post("2010-01-09-time-override.textile")
assert_equal "/2010/01/10/time-override.html", post.url
end

should "recognize category in yaml" do
post = setup_post("2009-01-27-category.textile")
assert post.categories.include?('foo')
Expand Down

0 comments on commit a1550b3

Please sign in to comment.