diff --git a/features/site_configuration.feature b/features/site_configuration.feature index c07a3c73..14f29be7 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -116,6 +116,46 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" + Scenario: Generate proper dates with explicitly set timezone (same as posts' time) + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }}" + And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | timezone | America/New_York | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. | + | entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2" in "_site/index.html" + And I should see "Post Layout:

content for entry1.

built at 2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html" + And I should see "Post Layout:

content for entry2.

built at 2013-04-10T03:14:00-04:00" in "_site/2013/04/10/entry2.html" + + Scenario: Generate proper dates with explicitly set timezone (different than posts' time) + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }}" + And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | timezone | Australia/Melbourne | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. | + | entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2" in "_site/index.html" + And the "_site/2013/04/10/entry1.html" file should exist + And the "_site/2013/04/10/entry2.html" file should exist + And I should see escaped "Post Layout:

content for entry1.

built at 2013-04-10T13:22:00+10:00" in "_site/2013/04/10/entry1.html" + And I should see escaped "Post Layout:

content for entry2.

built at 2013-04-10T17:14:00+10:00" in "_site/2013/04/10/entry2.html" + Scenario: Limit the number of posts generated by most recent date Given I have a _posts directory And I have a configuration file with: diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index fd58679d..c30b9034 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -1,4 +1,5 @@ Before do + FileUtils.rm_rf(TEST_DIR) FileUtils.mkdir(TEST_DIR) Dir.chdir(TEST_DIR) end @@ -61,7 +62,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire if "draft" == status path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}") else - date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d') + format = if has_time_component?(post['date']) + '%Y-%m-%d %H:%M %z' + else + '%m/%d/%Y' # why even + end + parsed_date = DateTime.strptime(post['date'], format) + post['date'] = parsed_date.to_s + date = parsed_date.strftime('%Y-%m-%d') path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}") end @@ -69,6 +77,9 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire %w(title layout tag tags category categories published author path).each do |key| matter_hash[key] = post[key] if post[key] end + if "post" == status + matter_hash["date"] = post["date"] if post["date"] + end matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp content = post['content'] @@ -134,7 +145,11 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert_match Regexp.new(text), File.open(file).readlines.join + assert Regexp.new(text).match(File.open(file).readlines.join) +end + +Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| + assert Regexp.new(Regexp.escape(text)).match(File.open(file).readlines.join) end Then /^the "(.*)" file should exist$/ do |file| diff --git a/features/support/env.rb b/features/support/env.rb index 7e550c6c..38bab950 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -7,7 +7,7 @@ World do end TEST_DIR = File.join('/', 'tmp', 'jekyll') -JEKYLL_PATH = File.join(ENV['PWD'], 'bin', 'jekyll') +JEKYLL_PATH = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll') def run_jekyll(opts = {}) command = JEKYLL_PATH.clone @@ -17,5 +17,9 @@ def run_jekyll(opts = {}) system command end +def has_time_component?(date_string) + date_string.split(" ").size > 1 +end + # work around "invalid option: --format" cucumber bug (see #296) Test::Unit.run = true if RUBY_VERSION < '1.9' diff --git a/lib/jekyll.rb b/lib/jekyll.rb index d8eb7a54..662a471c 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -73,6 +73,18 @@ module Jekyll config = config.read_config_files(config.config_files(override)) # Merge DEFAULTS < _config.yml < override - config.deep_merge(override).stringify_keys + config = config.deep_merge(override).stringify_keys + set_timezone(config['timezone']) if config['timezone'] + + config + end + + # Static: Set the TZ environment variable to use the timezone specified + # + # timezone - the IANA Time Zone + # + # Returns nothing + def self.set_timezone(timezone) + ENV['TZ'] = timezone end end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 9433a015..3544b98b 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -10,6 +10,8 @@ module Jekyll 'layouts' => '_layouts', 'keep_files' => ['.git','.svn'], + 'timezone' => nil, # use the local timezone + 'safe' => false, 'show_drafts' => nil, 'limit_posts' => nil, diff --git a/site/_posts/2012-07-01-configuration.md b/site/_posts/2012-07-01-configuration.md index 30e20f8d..1556d449 100644 --- a/site/_posts/2012-07-01-configuration.md +++ b/site/_posts/2012-07-01-configuration.md @@ -81,6 +81,22 @@ class="flag">flags (specified on the command-line) that control them.

include: [DIR, FILE, ...]

+ + +

Time Zone

+

+ Set the time zone for site generation. This sets the TZ + environment variable, which Ruby uses to handle time and date + creation and manipulation. Any entry from the + IANA Time Zone + Database is valid, e.g. America/New_York. The default + is the local time zone, as set by your operating system. +

+ + +

timezone: TIMEZONE

+ +