New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glob scope path only if configured with a pattern #6692
Changes from 2 commits
3ce57cd
28559b7
7764331
d409d4a
a69ffba
5b90b7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,21 +97,26 @@ def applies?(scope, path, type) | |
applies_path?(scope, path) && applies_type?(scope, type) | ||
end | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def applies_path?(scope, path) | ||
return true if !scope.key?("path") || scope["path"].empty? | ||
|
||
sanitized_path = Pathname.new(sanitize_path(path)) | ||
|
||
site_path = Pathname.new(@site.source) | ||
site_path = Pathname.new(@site.source) | ||
rel_scope_path = Pathname.new(scope["path"]) | ||
abs_scope_path = File.join(@site.source, rel_scope_path) | ||
Dir.glob(abs_scope_path).each do |scope_path| | ||
scope_path = Pathname.new(scope_path).relative_path_from site_path | ||
return true if path_is_subpath?(sanitized_path, scope_path) | ||
|
||
if glob_pattern?(rel_scope_path) | ||
Dir.glob(abs_scope_path).each do |scope_path| | ||
scope_path = Pathname.new(scope_path).relative_path_from site_path | ||
Jekyll.logger.debug "Globbed Scope Path:", scope_path | ||
return true if path_is_subpath?(sanitized_path, scope_path) | ||
end | ||
end | ||
|
||
path_is_subpath?(sanitized_path, rel_scope_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make this an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def path_is_subpath?(path, parent_path) | ||
path.ascend do |ascended_path| | ||
|
@@ -123,6 +128,13 @@ def path_is_subpath?(path, parent_path) | |
false | ||
end | ||
|
||
def glob_pattern?(path) | ||
path.each_filename do |str| | ||
return true if str =~ %r!\*+|\?|\[.*\]|{.*}! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to test the path component string for specific glob patterns. and regex seems better suited for it than multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashmaroli Why do we need to test each filename separately? AFAIK, the presence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
is also a glob pattern to catch all kinds of files with basename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen or used Let's decide which glob patterns we should support and write individual tests using them so we know they work and are supported. The original PR only mentioned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, for your example, I would have used |
||
end | ||
false | ||
end | ||
|
||
# Determines whether the scope applies to type. | ||
# The scope applies to the type if: | ||
# 1. no 'type' is specified | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead of this, we do
if scope["path"].to_s.include?("*")
. Or you can change the implementation ofglob_pattern?
to just dopath.to_s.include?("*")
. What do you think?