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
Scope path glob #6268
Scope path glob #6268
Changes from all commits
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 |
---|---|---|
|
@@ -100,12 +100,27 @@ def applies?(scope, path, type) | |
def applies_path?(scope, path) | ||
return true if !scope.key?("path") || scope["path"].empty? | ||
|
||
scope_path = Pathname.new(scope["path"]) | ||
Pathname.new(sanitize_path(path)).ascend do |ascended_path| | ||
if ascended_path.to_s == scope_path.to_s | ||
sanitized_path = Pathname.new(sanitize_path(path)) | ||
|
||
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) | ||
end | ||
|
||
path_is_subpath?(sanitized_path, rel_scope_path) | ||
end | ||
|
||
def path_is_subpath?(path, parent_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. do you want to expose this method as a 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 Isn't there a private scope starting right before 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. right.. my bad.. ignore.. |
||
path.ascend do |ascended_path| | ||
if ascended_path.to_s == parent_path.to_s | ||
return true | ||
end | ||
end | ||
|
||
false | ||
end | ||
|
||
# Determines whether the scope applies to type. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,30 @@ class TestFrontMatterDefaults < JekyllUnitTest | |
end | ||
end | ||
|
||
context "A site with full front matter defaults (glob)" do | ||
setup do | ||
@site = fixture_site({ | ||
"defaults" => [{ | ||
"scope" => { | ||
"path" => "contacts/*.html", | ||
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. What happens if I have 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. Since we're using 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. That's what would happen with the current code, yeah. I'm wondering if it makes sense to have 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. Seems to me that 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. It should definitely be documented! If you wanted to apply to just root, would 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. Well, it would, though it would definitely take more custom logic that using 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. Regarding the documentation - where should I write what? |
||
"type" => "page", | ||
}, | ||
"values" => { | ||
"key" => "val", | ||
}, | ||
},], | ||
}) | ||
@site.process | ||
@affected = @site.pages.find { |page| page.relative_path == "contacts/bar.html" } | ||
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } | ||
end | ||
|
||
should "affect only the specified path and type" do | ||
assert_equal @affected.data["key"], "val" | ||
assert_nil @not_affected.data["key"] | ||
end | ||
end | ||
|
||
context "A site with front matter type pages and an extension" do | ||
setup do | ||
@site = fixture_site({ | ||
|
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.
We have some code in
EntryFilter#glob_include?
we might be able to use here.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.
Looked through that code, it relies on
File#fnmatch?
that uses the same rules asDir#glob
, thoughEntryFilter#glob_include?
itself is not super-useful in this code, it would take more lines of code to reuseglob_include?