Merge pull request #1492 from maul-esel/publishing

This commit is contained in:
Matt Rogers 2014-04-14 20:17:01 -05:00
commit 6be33cf6ef
8 changed files with 51 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

21
lib/jekyll/publisher.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -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)