From e60e5f35327944bd2198cc19b54d27a1dffc9479 Mon Sep 17 00:00:00 2001 From: Ducksan Cho Date: Wed, 25 Nov 2015 23:18:33 +1300 Subject: [PATCH 1/3] Allow quoted date in front matter defaults --- lib/jekyll/frontmatter_defaults.rb | 9 ++++++++- test/test_front_matter_defaults.rb | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/frontmatter_defaults.rb b/lib/jekyll/frontmatter_defaults.rb index d6cb173f..d6fba04f 100644 --- a/lib/jekyll/frontmatter_defaults.rb +++ b/lib/jekyll/frontmatter_defaults.rb @@ -30,6 +30,13 @@ module Jekyll set end + def parse_quoted_date(set) + return set unless set.key?('values') && set['values'].key?('date') + return set if set['values']['date'].is_a?(Time) + set['values']['date'] = Utils.parse_date(set['values']['date'], "Front matter defaults does not have a valid date.") + set + end + # Finds a default value for a given setting, filtered by path and type # # path - the path (relative to the source) of the page, post or :draft the default is used in @@ -159,7 +166,7 @@ module Jekyll sets.map do |set| if valid?(set) - update_deprecated_types(set) + parse_quoted_date(update_deprecated_types(set)) else Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:" Jekyll.logger.warn "#{set}" diff --git a/test/test_front_matter_defaults.rb b/test/test_front_matter_defaults.rb index 99efedea..8eeed7f3 100644 --- a/test/test_front_matter_defaults.rb +++ b/test/test_front_matter_defaults.rb @@ -175,4 +175,29 @@ class TestFrontMatterDefaults < JekyllUnitTest end end + context "A site with front matter defaults with quoted date" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "values" => { + "date" => "2015-01-01 00:00:01" + } + }] + })) + end + + should "not raise error" do + @site.process + end + + should "parse date" do + @site.process + date = Time.parse("2015-01-01 00:00:01") + assert @site.pages.find { |page| page.data["date"] == date } + assert @site.posts.find { |page| page.data["date"] == date } + end + end + end From c159f19c7d92ca0f1b32f76f679e80dfc308173f Mon Sep 17 00:00:00 2001 From: Ducksan Cho Date: Thu, 26 Nov 2015 00:06:09 +1300 Subject: [PATCH 2/3] Rename destructive method with bang --- lib/jekyll/frontmatter_defaults.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/frontmatter_defaults.rb b/lib/jekyll/frontmatter_defaults.rb index d6fba04f..a37dcbe7 100644 --- a/lib/jekyll/frontmatter_defaults.rb +++ b/lib/jekyll/frontmatter_defaults.rb @@ -30,7 +30,7 @@ module Jekyll set end - def parse_quoted_date(set) + def ensure_time!(set) return set unless set.key?('values') && set['values'].key?('date') return set if set['values']['date'].is_a?(Time) set['values']['date'] = Utils.parse_date(set['values']['date'], "Front matter defaults does not have a valid date.") @@ -166,7 +166,7 @@ module Jekyll sets.map do |set| if valid?(set) - parse_quoted_date(update_deprecated_types(set)) + ensure_time!(update_deprecated_types(set)) else Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:" Jekyll.logger.warn "#{set}" From 99042fa8702189bbdd664946f962d0141e64206c Mon Sep 17 00:00:00 2001 From: Ducksan Cho Date: Sat, 5 Dec 2015 16:21:50 +1300 Subject: [PATCH 3/3] Improve error message --- lib/jekyll/frontmatter_defaults.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/frontmatter_defaults.rb b/lib/jekyll/frontmatter_defaults.rb index a37dcbe7..673d9a99 100644 --- a/lib/jekyll/frontmatter_defaults.rb +++ b/lib/jekyll/frontmatter_defaults.rb @@ -33,7 +33,7 @@ module Jekyll def ensure_time!(set) return set unless set.key?('values') && set['values'].key?('date') return set if set['values']['date'].is_a?(Time) - set['values']['date'] = Utils.parse_date(set['values']['date'], "Front matter defaults does not have a valid date.") + set['values']['date'] = Utils.parse_date(set['values']['date'], "An invalid date format was found in a front-matter default set: #{set}") set end