Merge pull request #5025 from ayastreb/regenerator
Merge pull request 5025
This commit is contained in:
commit
d093c76d35
|
@ -8,7 +8,6 @@ AllCops:
|
||||||
- lib/jekyll/configuration.rb
|
- lib/jekyll/configuration.rb
|
||||||
- lib/jekyll/convertible.rb
|
- lib/jekyll/convertible.rb
|
||||||
- lib/jekyll/document.rb
|
- lib/jekyll/document.rb
|
||||||
- lib/jekyll/regenerator.rb
|
|
||||||
- lib/jekyll/renderer.rb
|
- lib/jekyll/renderer.rb
|
||||||
- bin/**/*
|
- bin/**/*
|
||||||
- benchmark/**/*
|
- benchmark/**/*
|
||||||
|
|
|
@ -20,18 +20,14 @@ module Jekyll
|
||||||
def regenerate?(document)
|
def regenerate?(document)
|
||||||
case document
|
case document
|
||||||
when Page
|
when Page
|
||||||
document.asset_file? || document.data['regenerate'] ||
|
regenerate_page?(document)
|
||||||
source_modified_or_dest_missing?(
|
|
||||||
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
|
||||||
)
|
|
||||||
when Document
|
when Document
|
||||||
!document.write? || document.data['regenerate'] ||
|
regenerate_document?(document)
|
||||||
source_modified_or_dest_missing?(
|
|
||||||
document.path, document.destination(@site.dest)
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
source_path = document.respond_to?(:path) ? document.path : nil
|
source_path = document.respond_to?(:path) ? document.path : nil
|
||||||
dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil
|
dest_path = if document.respond_to?(:destination)
|
||||||
|
document.destination(@site.dest)
|
||||||
|
end
|
||||||
source_modified_or_dest_missing?(source_path, dest_path)
|
source_modified_or_dest_missing?(source_path, dest_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -94,25 +90,16 @@ module Jekyll
|
||||||
return cache[path]
|
return cache[path]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check path that exists in metadata
|
if metadata[path]
|
||||||
data = metadata[path]
|
# If we have seen this file before,
|
||||||
if data
|
# check if it or one of its dependencies has been modified
|
||||||
data["deps"].each do |dependency|
|
existing_file_modified?(path)
|
||||||
if modified?(dependency)
|
|
||||||
return cache[dependency] = cache[path] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if File.exist?(path) && data["mtime"].eql?(File.mtime(path))
|
|
||||||
return cache[path] = false
|
|
||||||
else
|
else
|
||||||
return add(path)
|
# If we have not seen this file before, add it to the metadata and regenerate it
|
||||||
|
add(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Path does not exist in metadata, add it
|
|
||||||
return add(path)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add a dependency of a path
|
# Add a dependency of a path
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
|
@ -139,7 +126,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the String path of the file.
|
# Returns the String path of the file.
|
||||||
def metadata_file
|
def metadata_file
|
||||||
site.in_source_dir('.jekyll-metadata')
|
site.in_source_dir(".jekyll-metadata")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if metadata has been disabled
|
# Check if metadata has been disabled
|
||||||
|
@ -173,5 +160,40 @@ module Jekyll
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def regenerate_page?(document)
|
||||||
|
document.asset_file? || document.data["regenerate"] ||
|
||||||
|
source_modified_or_dest_missing?(
|
||||||
|
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def regenerate_document?(document)
|
||||||
|
!document.write? || document.data["regenerate"] ||
|
||||||
|
source_modified_or_dest_missing?(
|
||||||
|
document.path, document.destination(@site.dest)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def existing_file_modified?(path)
|
||||||
|
# If one of this file dependencies have been modified,
|
||||||
|
# set the regeneration bit for both the dependency and the file to true
|
||||||
|
metadata[path]["deps"].each do |dependency|
|
||||||
|
if modified?(dependency)
|
||||||
|
return cache[dependency] = cache[path] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if File.exist?(path) && metadata[path]["mtime"].eql?(File.mtime(path))
|
||||||
|
# If this file has not been modified, set the regeneration bit to false
|
||||||
|
cache[path] = false
|
||||||
|
else
|
||||||
|
# If it has been modified, set it to true
|
||||||
|
add(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue