Cache globbed paths in front matter defaults (#7345)
Merge pull request 7345
This commit is contained in:
parent
46be718ef6
commit
b4dcdd42f8
|
@ -10,6 +10,11 @@ module Jekyll
|
||||||
# Initializes a new instance.
|
# Initializes a new instance.
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
|
reset
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset
|
||||||
|
@glob_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_deprecated_types(set)
|
def update_deprecated_types(set)
|
||||||
|
@ -98,28 +103,35 @@ module Jekyll
|
||||||
applies_type?(scope, type) && applies_path?(scope, path)
|
applies_type?(scope, type) && applies_path?(scope, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
|
||||||
def applies_path?(scope, path)
|
def applies_path?(scope, path)
|
||||||
return true if !scope.key?("path") || scope["path"].empty?
|
return true if !scope.key?("path") || scope["path"].empty?
|
||||||
|
|
||||||
sanitized_path = Pathname.new(sanitize_path(path))
|
sanitized_path = Pathname.new(sanitize_path(path))
|
||||||
site_path = Pathname.new(@site.source)
|
|
||||||
rel_scope_path = Pathname.new(scope["path"])
|
rel_scope_path = Pathname.new(scope["path"])
|
||||||
abs_scope_path = File.join(@site.source, rel_scope_path)
|
|
||||||
|
|
||||||
if scope["path"].to_s.include?("*")
|
if scope["path"].to_s.include?("*")
|
||||||
Dir.glob(abs_scope_path).each do |scope_path|
|
glob_scope(sanitized_path, rel_scope_path)
|
||||||
scope_path = Pathname.new(scope_path).relative_path_from(site_path)
|
else
|
||||||
|
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def glob_scope(sanitized_path, rel_scope_path)
|
||||||
|
site_source = Pathname.new(@site.source)
|
||||||
|
abs_scope_path = site_source.join(rel_scope_path).to_s
|
||||||
|
|
||||||
|
glob_cache(abs_scope_path).each do |scope_path|
|
||||||
|
scope_path = Pathname.new(scope_path).relative_path_from(site_source)
|
||||||
scope_path = strip_collections_dir(scope_path)
|
scope_path = strip_collections_dir(scope_path)
|
||||||
Jekyll.logger.debug "Globbed Scope Path:", scope_path
|
Jekyll.logger.debug "Globbed Scope Path:", scope_path
|
||||||
return true if path_is_subpath?(sanitized_path, scope_path)
|
return true if path_is_subpath?(sanitized_path, scope_path)
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
else
|
|
||||||
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def glob_cache(path)
|
||||||
|
@glob_cache[path] ||= Dir.glob(path)
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/AbcSize
|
|
||||||
|
|
||||||
def path_is_subpath?(path, parent_path)
|
def path_is_subpath?(path, parent_path)
|
||||||
path.ascend do |ascended_path|
|
path.ascend do |ascended_path|
|
||||||
|
|
|
@ -83,6 +83,8 @@ module Jekyll
|
||||||
Jekyll.logger.info @liquid_renderer.stats_table
|
Jekyll.logger.info @liquid_renderer.stats_table
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
|
#
|
||||||
# Reset Site details.
|
# Reset Site details.
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
|
@ -104,12 +106,14 @@ module Jekyll
|
||||||
@regenerator.clear_cache
|
@regenerator.clear_cache
|
||||||
@liquid_renderer.reset
|
@liquid_renderer.reset
|
||||||
@site_cleaner = nil
|
@site_cleaner = nil
|
||||||
|
frontmatter_defaults.reset
|
||||||
|
|
||||||
raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative?
|
raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative?
|
||||||
|
|
||||||
Jekyll::Cache.clear_if_config_changed config
|
Jekyll::Cache.clear_if_config_changed config
|
||||||
Jekyll::Hooks.trigger :site, :after_reset, self
|
Jekyll::Hooks.trigger :site, :after_reset, self
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
# Load necessary libraries, plugins, converters, and generators.
|
# Load necessary libraries, plugins, converters, and generators.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue