Implement @mattr-'s suggestions

This commit is contained in:
Alfred Xing 2014-11-21 22:10:08 -08:00
parent fe6bfc6f1b
commit ac03af3229
7 changed files with 24 additions and 15 deletions

View File

@ -13,7 +13,7 @@ module Jekyll
# Cleans up the site's destination directory # Cleans up the site's destination directory
def cleanup! def cleanup!
FileUtils.rm_rf(obsolete_files) FileUtils.rm_rf(obsolete_files)
FileUtils.rm_rf(metadata_file) if @site.config["clean"] FileUtils.rm_rf(metadata_file) if @site.config["full_rebuild"]
end end
private private

View File

@ -58,7 +58,7 @@ module Jekyll
c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished' 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.'
c.option 'clean', '-c', '--clean', 'Clean the site before rebuilding.' c.option 'full_rebuild', '-f', '--full-rebuild', 'Clean the site before rebuilding.'
end end
end end

View File

@ -17,7 +17,7 @@ module Jekyll
# Handling Reading # Handling Reading
'safe' => false, 'safe' => false,
'include' => ['.htaccess'], 'include' => ['.htaccess'],
'exclude' => ['.jekyll-metadata'], 'exclude' => [],
'keep_files' => ['.git','.svn'], 'keep_files' => ['.git','.svn'],
'encoding' => 'utf-8', 'encoding' => 'utf-8',
'markdown_ext' => 'markdown,mkdown,mkdn,mkd,md', 'markdown_ext' => 'markdown,mkdown,mkdn,mkd,md',

View File

@ -7,9 +7,8 @@ module Jekyll
def initialize(site) def initialize(site)
@site = site @site = site
# Initialize metadata store by reading YAML file, # Read metadata from file
# or an empty hash if file does not exist read_metadata
@metadata = (File.file?(metadata_file) && !(site.config['clean'])) ? SafeYAML.load(File.read(metadata_file)) : {}
# Initialize cache to an empty hash # Initialize cache to an empty hash
@cache = {} @cache = {}
@ -92,5 +91,15 @@ module Jekyll
def metadata_file def metadata_file
Jekyll.sanitized_path(site.source, '.jekyll-metadata') Jekyll.sanitized_path(site.source, '.jekyll-metadata')
end end
private
# Read metadata from the metadata file, if no file is found,
# initialize with an empty hash
#
# Returns the read metadata.
def read_metadata
@metadata = (File.file?(metadata_file) && !(site.config['full_rebuild'])) ? SafeYAML.load(File.read(metadata_file)) : {}
end
end end
end end

View File

@ -294,7 +294,7 @@ module Jekyll
collections.each do |label, collection| collections.each do |label, collection|
collection.docs.each do |document| collection.docs.each do |document|
document.output = Jekyll::Renderer.new(self, document).run if ( document.output = Jekyll::Renderer.new(self, document).run if (
@metadata.regenerate?(document.path, document.write?) || metadata.regenerate?(document.path, document.write?) ||
document.data['regenerate'] document.data['regenerate']
) )
end end
@ -303,7 +303,7 @@ module Jekyll
payload = site_payload payload = site_payload
[posts, pages].flatten.each do |page_or_post| [posts, pages].flatten.each do |page_or_post|
page_or_post.render(layouts, payload) if ( page_or_post.render(layouts, payload) if (
@metadata.regenerate?(Jekyll.sanitized_path(source, page_or_post.relative_path)) || metadata.regenerate?(Jekyll.sanitized_path(source, page_or_post.relative_path)) ||
page_or_post.data['regenerate'] page_or_post.data['regenerate']
) )
end end
@ -324,11 +324,11 @@ module Jekyll
def write def write
each_site_file { |item| each_site_file { |item|
item.write(dest) if ( item.write(dest) if (
@metadata.regenerate?(Jekyll.sanitized_path(source, item.path)) || metadata.regenerate?(Jekyll.sanitized_path(source, item.path)) ||
(item.respond_to?(:data) && item.data['regenerate']) (item.respond_to?(:data) && item.data['regenerate'])
) )
} }
@metadata.write metadata.write
end end
# Construct a Hash of Posts indexed by the specified Post attribute. # Construct a Hash of Posts indexed by the specified Post attribute.

View File

@ -247,7 +247,7 @@ class TestDocument < Test::Unit::TestCase
}, },
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"clean" => true "full_rebuild" => true
})) }))
@site.process @site.process
@document = @site.collections["slides"].files.find { |doc| doc.relative_path == "_slides/octojekyll.png" } @document = @site.collections["slides"].files.find { |doc| doc.relative_path == "_slides/octojekyll.png" }

View File

@ -331,7 +331,7 @@ class TestSite < Test::Unit::TestCase
end end
bad_processor = "Custom::Markdown" bad_processor = "Custom::Markdown"
s = Site.new(site_configuration('markdown' => bad_processor, 'clean' => true)) s = Site.new(site_configuration('markdown' => bad_processor, 'full_rebuild' => true))
assert_raise Jekyll::Errors::FatalException do assert_raise Jekyll::Errors::FatalException do
s.process s.process
end end
@ -351,7 +351,7 @@ class TestSite < Test::Unit::TestCase
should 'throw FatalException at process time' do should 'throw FatalException at process time' do
bad_processor = 'not a processor name' bad_processor = 'not a processor name'
s = Site.new(site_configuration('markdown' => bad_processor, 'clean' => true)) s = Site.new(site_configuration('markdown' => bad_processor, 'full_rebuild' => true))
assert_raise Jekyll::Errors::FatalException do assert_raise Jekyll::Errors::FatalException do
s.process s.process
end end
@ -422,7 +422,7 @@ class TestSite < Test::Unit::TestCase
context "manipulating the Jekyll environment" do context "manipulating the Jekyll environment" do
setup do setup do
@site = Site.new(site_configuration({ @site = Site.new(site_configuration({
"clean" => true 'full_rebuild' => true
})) }))
@site.process @site.process
@page = @site.pages.find { |p| p.name == "environment.html" } @page = @site.pages.find { |p| p.name == "environment.html" }
@ -436,7 +436,7 @@ class TestSite < Test::Unit::TestCase
setup do setup do
ENV["JEKYLL_ENV"] = "production" ENV["JEKYLL_ENV"] = "production"
@site = Site.new(site_configuration({ @site = Site.new(site_configuration({
"clean" => true 'full_rebuild' => true
})) }))
@site.process @site.process
@page = @site.pages.find { |p| p.name == "environment.html" } @page = @site.pages.find { |p| p.name == "environment.html" }