From a1550b3378386ef89ad8cd2118ab99237579db04 Mon Sep 17 00:00:00 2001 From: Kris Brown Date: Sun, 10 Jan 2010 21:21:54 +0000 Subject: [PATCH] allow date to be specified in the front matter and override the value from the file name, fixes #62 and #38 --- lib/jekyll/post.rb | 7 +++++++ test/source/_posts/2010-01-09-date-override.textile | 5 +++++ test/source/_posts/2010-01-09-time-override.textile | 5 +++++ test/test_generated_site.rb | 2 +- test/test_post.rb | 10 ++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/source/_posts/2010-01-09-date-override.textile create mode 100644 test/source/_posts/2010-01-09-time-override.textile diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 914cfd59..c58f46e6 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -41,6 +41,13 @@ module Jekyll 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 diff --git a/test/source/_posts/2010-01-09-date-override.textile b/test/source/_posts/2010-01-09-date-override.textile new file mode 100644 index 00000000..efe8af4a --- /dev/null +++ b/test/source/_posts/2010-01-09-date-override.textile @@ -0,0 +1,5 @@ +--- +date: 2010-01-10 +--- + +Post with a front matter date diff --git a/test/source/_posts/2010-01-09-time-override.textile b/test/source/_posts/2010-01-09-time-override.textile new file mode 100644 index 00000000..7f80065a --- /dev/null +++ b/test/source/_posts/2010-01-09-time-override.textile @@ -0,0 +1,5 @@ +--- +date: 2010-01-10 13:07:09 +--- + +Post with a front matter time diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 357dd4db..46e0a75d 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -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 diff --git a/test/test_post.rb b/test/test_post.rb index b4b4502d..5cc11eaa 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -224,6 +224,16 @@ class TestPost < Test::Unit::TestCase 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')