diff --git a/bin/jekyll b/bin/jekyll index 6e03d48b..7ffd9d5d 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -48,6 +48,18 @@ opts = OptionParser.new do |opts| options['markdown'] = 'rdiscount' end + opts.on("--time [TIME]", "Time to generate the site for") do |time| + options['time'] = Time.parse(time) + end + + opts.on("--future", "Render future dated posts") do + options['future'] = true + end + + opts.on("--no-future", "Do not render future dated posts") do + options['future'] = false + end + opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style| options['permalink'] = style unless style.nil? end diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 31b8c71e..6f1c600e 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -33,7 +33,7 @@ Feature: Site configuration And I have an "README" file that contains "I want to be excluded" And I have an "index.html" file that contains "I want to be included" And I have a configuration file with "exclude" set to: - | Value | + | value | | README | | Rakefile | When I run jekyll @@ -61,3 +61,43 @@ Feature: Site configuration When I run jekyll Then the _site directory should exist And I should see "puts 'Hello world!'" in "_site/index.html" + + Scenario: Set time and no future dated posts + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}" + And I have a post layout that contains "Post Layout: {{ content }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | time | 2010-01-01 | + | future | false | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 12/31/2007 | post | content for entry1. | + | entry2 | 01/31/2020 | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 1 on 2010-01-01" in "_site/index.html" + And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" + And the "_site/2020/01/31/entry2.html" file should not exist + + Scenario: Set time and future dated posts allowed + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}" + And I have a post layout that contains "Post Layout: {{ content }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | time | 2010-01-01 | + | future | true | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 12/31/2007 | post | content for entry1. | + | entry2 | 01/31/2020 | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html" + 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" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 38a87c37..71b71d38 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -81,7 +81,16 @@ end Given /^I have a configuration file with "(.*)" set to "(.*)"$/ do |key, value| File.open('_config.yml', 'w') do |f| - f.write("#{key}: #{value}") + f.write("#{key}: #{value}\n") + f.close + end +end + +Given /^I have a configuration file with:$/ do |table| + File.open('_config.yml', 'w') do |f| + table.hashes.each do |row| + f.write("#{row["key"]}: #{row["value"]}\n") + end f.close end end @@ -90,7 +99,7 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table| File.open('_config.yml', 'w') do |f| f.write("#{key}:\n") table.hashes.each do |row| - f.write("- #{row["Value"]}\n") + f.write("- #{row["value"]}\n") end f.close end diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 0e631b51..05c539ff 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -39,6 +39,7 @@ module Jekyll 'source' => '.', 'destination' => File.join('.', '_site'), + 'future' => true, 'lsi' => false, 'pygments' => false, 'markdown' => 'maruku', diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 59a6acd8..286d02dc 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -2,7 +2,8 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, - :source, :dest, :lsi, :pygments, :permalink_style, :tags + :source, :dest, :lsi, :pygments, :permalink_style, :tags, :time, + :future # Initialize the site # +config+ is a Hash containing site configurations details @@ -17,12 +18,14 @@ module Jekyll self.pygments = config['pygments'] self.permalink_style = config['permalink'].to_sym self.exclude = config['exclude'] || [] + self.future = config['future'] self.reset self.setup end def reset + self.time = Time.parse(self.config['time'].to_s) || Time.now self.layouts = {} self.posts = [] self.pages = [] @@ -135,7 +138,7 @@ module Jekyll if Post.valid?(f) post = Post.new(self, self.source, dir, f) - if post.published + if post.published && (self.future || post.date <= self.time) self.posts << post post.categories.each { |c| self.categories[c] << post } post.tags.each { |c| self.tags[c] << post } @@ -230,7 +233,7 @@ module Jekyll # "categories" => []} def site_payload {"site" => self.config.merge({ - "time" => Time.now, + "time" => self.time, "posts" => self.posts.sort { |a,b| b <=> a }, "categories" => post_attr_hash('categories'), "tags" => post_attr_hash('tags')})} diff --git a/test/test_site.rb b/test/test_site.rb index b92bc496..705d0d09 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -22,6 +22,7 @@ class TestSite < Test::Unit::TestCase before_tags = @site.tags.length before_pages = @site.pages.length before_static_files = @site.static_files.length + before_time = @site.time @site.process assert_equal before_posts, @site.posts.length @@ -30,6 +31,7 @@ class TestSite < Test::Unit::TestCase assert_equal before_tags, @site.tags.length assert_equal before_pages, @site.pages.length assert_equal before_static_files, @site.static_files.length + assert before_time <= @site.time end should "read layouts" do