Merge pull request #1492 from maul-esel/publishing
This commit is contained in:
commit
6be33cf6ef
|
@ -139,3 +139,20 @@ Feature: Create sites
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
Then the _site/test directory should exist
|
Then the _site/test directory should exist
|
||||||
And I should see "some other stuff" in "_site/test/index.html"
|
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
|
||||||
|
|
|
@ -130,9 +130,8 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When /^I run jekyll(?: with "(.+)")?$/ do |opt|
|
||||||
When /^I run jekyll$/ do
|
run_jekyll_build(opt)
|
||||||
run_jekyll_build
|
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I run jekyll in safe mode$/ do
|
When /^I run jekyll in safe mode$/ do
|
||||||
|
|
|
@ -50,6 +50,7 @@ require 'jekyll/related_posts'
|
||||||
require 'jekyll/cleaner'
|
require 'jekyll/cleaner'
|
||||||
require 'jekyll/entry_filter'
|
require 'jekyll/entry_filter'
|
||||||
require 'jekyll/layout_reader'
|
require 'jekyll/layout_reader'
|
||||||
|
require 'jekyll/publisher'
|
||||||
|
|
||||||
# extensions
|
# extensions
|
||||||
require 'jekyll/plugin'
|
require 'jekyll/plugin'
|
||||||
|
|
|
@ -70,6 +70,7 @@ module Jekyll
|
||||||
c.option 'force_polling', '--force_polling', 'Force watch to use polling'
|
c.option 'force_polling', '--force_polling', 'Force watch to use polling'
|
||||||
c.option 'lsi', '--lsi', 'Use LSI for improved related posts'
|
c.option 'lsi', '--lsi', 'Use LSI for improved related posts'
|
||||||
c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder'
|
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 'quiet', '-q', '--quiet', 'Silence output.'
|
||||||
c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
|
c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,7 @@ module Jekyll
|
||||||
'limit_posts' => 0,
|
'limit_posts' => 0,
|
||||||
'lsi' => false,
|
'lsi' => false,
|
||||||
'future' => true, # remove and make true just default
|
'future' => true, # remove and make true just default
|
||||||
|
'unpublished' => false,
|
||||||
|
|
||||||
'relative_permalinks' => true, # backwards-compatibility with < 1.0
|
'relative_permalinks' => true, # backwards-compatibility with < 1.0
|
||||||
# will be set to false once 2.0 hits
|
# will be set to false once 2.0 hits
|
||||||
|
|
|
@ -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
|
|
@ -2,7 +2,7 @@ module Jekyll
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||||
:exclude, :include, :source, :dest, :lsi, :highlighter,
|
: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,
|
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems,
|
||||||
:plugin_manager
|
:plugin_manager
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ module Jekyll
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
self.config = config.clone
|
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])
|
self.send("#{opt}=", config[opt])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ module Jekyll
|
||||||
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
|
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
|
||||||
elsif has_yaml_header?(f_abs)
|
elsif has_yaml_header?(f_abs)
|
||||||
page = Page.new(self, source, dir, f)
|
page = Page.new(self, source, dir, f)
|
||||||
pages << page if page.published?
|
pages << page if publisher.publish?(page)
|
||||||
else
|
else
|
||||||
static_files << StaticFile.new(self, source, dir, f)
|
static_files << StaticFile.new(self, source, dir, f)
|
||||||
end
|
end
|
||||||
|
@ -134,9 +134,7 @@ module Jekyll
|
||||||
posts = read_content(dir, '_posts', Post)
|
posts = read_content(dir, '_posts', Post)
|
||||||
|
|
||||||
posts.each do |post|
|
posts.each do |post|
|
||||||
if post.published? && (future || post.date <= time)
|
aggregate_post_info(post) if publisher.publish?(post)
|
||||||
aggregate_post_info(post)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -391,5 +389,9 @@ module Jekyll
|
||||||
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
||||||
name.gsub(/\s+/, '_')
|
name.gsub(/\s+/, '_')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publisher
|
||||||
|
@publisher ||= Publisher.new(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -415,16 +415,6 @@ class TestPost < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "initializing posts" do
|
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
|
should "recognize date in yaml" do
|
||||||
post = setup_post("2010-01-09-date-override.textile")
|
post = setup_post("2010-01-09-date-override.textile")
|
||||||
do_render(post)
|
do_render(post)
|
||||||
|
|
Loading…
Reference in New Issue