make sure pages with published being false are not generated

This commit is contained in:
liufengyun 2014-01-12 17:40:14 +08:00
parent e7139cbd85
commit 22e1e5f28c
7 changed files with 27 additions and 15 deletions

View File

@ -21,6 +21,11 @@ module Jekyll
self.content || '' self.content || ''
end end
# Whether the file is published or not, as indicated in YAML front-matter
def published?
!(self.data.has_key?('published') && self.data['published'] == false)
end
# Returns merged option hash for File.read of self.site (if exists) # Returns merged option hash for File.read of self.site (if exists)
# and a given param # and a given param
def merged_file_read_opts(opts) def merged_file_read_opts(opts)

View File

@ -35,7 +35,7 @@ module Jekyll
attr_accessor :site attr_accessor :site
attr_accessor :data, :extracted_excerpt, :content, :output, :ext attr_accessor :data, :extracted_excerpt, :content, :output, :ext
attr_accessor :date, :slug, :published, :tags, :categories attr_accessor :date, :slug, :tags, :categories
attr_reader :name attr_reader :name
@ -60,20 +60,10 @@ module Jekyll
self.date = Time.parse(self.data["date"].to_s) self.date = Time.parse(self.data["date"].to_s)
end end
self.published = self.published?
self.populate_categories self.populate_categories
self.populate_tags self.populate_tags
end end
def published?
if self.data.has_key?('published') && self.data['published'] == false
false
else
true
end
end
def populate_categories def populate_categories
if self.categories.empty? if self.categories.empty?
self.categories = self.data.pluralized_array('category', 'categories').map {|c| c.to_s.downcase} self.categories = self.data.pluralized_array('category', 'categories').map {|c| c.to_s.downcase}

View File

@ -170,7 +170,8 @@ module Jekyll
f_rel = File.join(dir, f) f_rel = File.join(dir, f)
read_directories(f_rel) unless self.dest.sub(/\/$/, '') == f_abs read_directories(f_rel) unless self.dest.sub(/\/$/, '') == f_abs
elsif has_yaml_header?(f_abs) elsif has_yaml_header?(f_abs)
pages << Page.new(self, self.source, dir, f) page = Page.new(self, self.source, dir, f)
pages << page if page.published?
else else
static_files << StaticFile.new(self, self.source, dir, f) static_files << StaticFile.new(self, self.source, dir, f)
end end
@ -189,7 +190,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 && (self.future || post.date <= self.time) if post.published? && (self.future || post.date <= self.time)
aggregate_post_info(post) aggregate_post_info(post)
end end
end end

View File

@ -0,0 +1,7 @@
---
layout: default
title: Not published!
published: false
---
This should *not* be published!

View File

@ -32,6 +32,10 @@ class TestGeneratedSite < Test::Unit::TestCase
assert_equal "published.html", published.first assert_equal "published.html", published.first
end end
should "hide unpublished page" do
assert !File.exists?(dest_dir('/unpublished.html'))
end
should "not copy _posts directory" do should "not copy _posts directory" do
assert !File.exist?(dest_dir('_posts')) assert !File.exist?(dest_dir('_posts'))
end end

View File

@ -25,6 +25,11 @@ class TestPage < Test::Unit::TestCase
assert_equal "/contacts.html", @page.url assert_equal "/contacts.html", @page.url
end end
should "not published when published yaml is false" do
@page = setup_page("unpublished.html")
assert_equal false, @page.published?
end
context "in a directory hierarchy" do context "in a directory hierarchy" do
should "create url based on filename" do should "create url based on filename" do
@page = setup_page('/contacts', 'bar.html') @page = setup_page('/contacts', 'bar.html')

View File

@ -387,12 +387,12 @@ class TestPost < Test::Unit::TestCase
context "initializing posts" do context "initializing posts" do
should "publish when published yaml is no specified" do should "publish when published yaml is no specified" do
post = setup_post("2008-02-02-published.textile") post = setup_post("2008-02-02-published.textile")
assert_equal true, post.published assert_equal true, post.published?
end end
should "not published when published yaml is false" do should "not published when published yaml is false" do
post = setup_post("2008-02-02-not-published.textile") post = setup_post("2008-02-02-not-published.textile")
assert_equal false, post.published assert_equal false, post.published?
end end
should "recognize date in yaml" do should "recognize date in yaml" do