Allow documents to set `published` in front matter

This commit is contained in:
Alfred Xing 2014-11-29 10:51:30 -08:00
parent f3a274377a
commit 7655b533c9
3 changed files with 47 additions and 1 deletions

View File

@ -40,7 +40,7 @@ module Jekyll
if Utils.has_yaml_header? full_path
doc = Jekyll::Document.new(full_path, { site: site, collection: self })
doc.read
docs << doc
docs << doc if publisher.publish?(doc)
else
relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.")
files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self)
@ -184,5 +184,16 @@ module Jekyll
end
end
private
# A Publisher object used to determine which documents should be
# added to the docs list
#
# Returns a Publisher object.
def publisher
@publisher ||= Publisher.new(site)
end
end
end

View File

@ -0,0 +1,7 @@
---
title: Non outputted slide
layout: slide
published: false
---
This should not be output

View File

@ -237,6 +237,34 @@ class TestDocument < Test::Unit::TestCase
end
end
context "documents in a collection" do
setup do
@site = Site.new(Jekyll.configuration({
"collections" => {
"slides" => {
"output" => true
}
},
"source" => source_dir,
"destination" => dest_dir
}))
@site.process
@files = @site.collections["slides"].docs
end
context "without output overrides" do
should "be output according to collection defaults" do
assert_not_nil @files.find { |doc| doc.relative_path == "_slides/example-slide-4.html" }
end
end
context "with output overrides" do
should "be output according its front matter" do
assert_nil @files.find { |doc| doc.relative_path == "_slides/non-outputted-slide.html" }
end
end
end
context "a static file in a collection" do
setup do
@site = Site.new(Jekyll.configuration({