diff --git a/features/create_sites.feature b/features/create_sites.feature index 5d22397b..c84d90f8 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -139,3 +139,20 @@ Feature: Create sites When I run jekyll Then the _site/test directory should exist And I should see "some other stuff" in "_site/test/index.html" + + Scenario: Basic site with unpublished page + Given I have an "index.html" page with title "index" that contains "Published page" + And I have a "public.html" page with published "true" that contains "Explicitly published page" + And I have a "secret.html" page with published "false" that contains "Unpublished page" + + When I run jekyll + Then the _site directory should exist + And the "_site/index.html" file should exist + And the "_site/public.html" file should exist + But the "_site/secret.html" file should not exist + + When I run jekyll with "--unpublished" + Then the _site directory should exist + And the "_site/index.html" file should exist + And the "_site/public.html" file should exist + And the "_site/secret.html" file should exist diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 00264fb6..93de5c10 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -130,9 +130,8 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table| end end - -When /^I run jekyll$/ do - run_jekyll_build +When /^I run jekyll(?: with "(.+)")?$/ do |opt| + run_jekyll_build(opt) end When /^I run jekyll in safe mode$/ do diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 604ff238..e2dd369c 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -50,6 +50,7 @@ require 'jekyll/related_posts' require 'jekyll/cleaner' require 'jekyll/entry_filter' require 'jekyll/layout_reader' +require 'jekyll/publisher' # extensions require 'jekyll/plugin' diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index 957e9825..62a532f6 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -70,6 +70,7 @@ module Jekyll c.option 'force_polling', '--force_polling', 'Force watch to use polling' c.option 'lsi', '--lsi', 'Use LSI for improved related posts' c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder' + c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished' c.option 'quiet', '-q', '--quiet', 'Silence output.' c.option 'verbose', '-V', '--verbose', 'Print verbose output.' end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 091bebc4..93dc5193 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -24,6 +24,7 @@ module Jekyll 'limit_posts' => 0, 'lsi' => false, 'future' => true, # remove and make true just default + 'unpublished' => false, 'relative_permalinks' => true, # backwards-compatibility with < 1.0 # will be set to false once 2.0 hits diff --git a/lib/jekyll/publisher.rb b/lib/jekyll/publisher.rb new file mode 100644 index 00000000..e86e96b6 --- /dev/null +++ b/lib/jekyll/publisher.rb @@ -0,0 +1,21 @@ +module Jekyll + class Publisher + def initialize(site) + @site = site + end + + def publish?(thing) + can_be_published?(thing) && !hidden_in_the_future?(thing) + end + + private + + def can_be_published?(thing) + thing.data.fetch('published', true) || @site.unpublished + end + + def hidden_in_the_future?(thing) + thing.is_a?(Post) && !@site.future && thing.date > @site.time + end + end +end \ No newline at end of file diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index b5ff5eb4..14224898 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -2,7 +2,7 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :exclude, :include, :source, :dest, :lsi, :highlighter, - :permalink_style, :time, :future, :safe, :plugins, :limit_posts, + :permalink_style, :time, :future, :unpublished, :safe, :plugins, :limit_posts, :show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems, :plugin_manager @@ -14,7 +14,7 @@ module Jekyll def initialize(config) self.config = config.clone - %w[safe lsi highlighter baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt| + %w[safe lsi highlighter baseurl exclude include future unpublished show_drafts limit_posts keep_files gems].each do |opt| self.send("#{opt}=", config[opt]) end @@ -115,7 +115,7 @@ module Jekyll read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs elsif has_yaml_header?(f_abs) page = Page.new(self, source, dir, f) - pages << page if page.published? + pages << page if publisher.publish?(page) else static_files << StaticFile.new(self, source, dir, f) end @@ -134,9 +134,7 @@ module Jekyll posts = read_content(dir, '_posts', Post) posts.each do |post| - if post.published? && (future || post.date <= time) - aggregate_post_info(post) - end + aggregate_post_info(post) if publisher.publish?(post) end end @@ -391,5 +389,9 @@ module Jekyll name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') name.gsub(/\s+/, '_') end + + def publisher + @publisher ||= Publisher.new(self) + end end end diff --git a/test/test_post.rb b/test/test_post.rb index d7a57510..9f963d0f 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -415,16 +415,6 @@ class TestPost < Test::Unit::TestCase end context "initializing posts" do - should "publish when published yaml is no specified" do - post = setup_post("2008-02-02-published.textile") - assert_equal true, post.published? - end - - should "not published when published yaml is false" do - post = setup_post("2008-02-02-not-published.textile") - assert_equal false, post.published? - end - should "recognize date in yaml" do post = setup_post("2010-01-09-date-override.textile") do_render(post)