Restore globbed path behavior in front matter defaults (#9762)

Restore existing behavior in v4.3.x wherein a scope with path
`_*/**/index.md` matches `_label/index.md` as well instead of just
`_label/dir/index.md`.
This commit is contained in:
Ashwin Maroli 2025-01-29 18:01:40 +05:30 committed by GitHub
parent 33e8a84a00
commit c5cd1fb04f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 7 additions and 40 deletions

View File

@ -109,7 +109,7 @@ module Jekyll
sanitized_path = sanitize_path(path) sanitized_path = sanitize_path(path)
if rel_scope_path.include?("*") if rel_scope_path.include?("*")
File.fnmatch?(strip_collections_dir(rel_scope_path), sanitized_path) glob_scope(sanitized_path, rel_scope_path)
else else
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path)) path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
end end

View File

@ -1 +0,0 @@
<svg></svg>

Before

Width:  |  Height:  |  Size: 13 B

View File

@ -1,3 +0,0 @@
---
speciality: Ruby
---

View File

@ -1 +0,0 @@
<svg></svg>

Before

Width:  |  Height:  |  Size: 13 B

View File

@ -1,3 +0,0 @@
---
speciality: JS Frameworks
---

View File

@ -25,6 +25,10 @@ class TestFrontMatterDefaults < JekyllUnitTest
assert_equal "val", @affected.data["key"] assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
should "not call Dir.glob block" do
refute_includes @output, "Globbed Scope Path:"
end
end end
context "A site with full front matter defaults (glob)" do context "A site with full front matter defaults (glob)" do
@ -49,38 +53,9 @@ class TestFrontMatterDefaults < JekyllUnitTest
assert_equal "val", @affected.data["key"] assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
end
context "A site with collections and front matter defaults with glob patterns" do should "call Dir.glob block" do
setup do assert_includes @output, "Globbed Scope Path:"
site = fixture_site(
"collections_dir" => "gathering",
"collections" => { "staff" => { "output" => true } },
"defaults" => [
{
"scope" => { "path" => "_staff/**/*.md", "type" => "staff" },
"values" => { "layout" => "simple" },
},
{
"scope" => { "path" => "_staff/**/*.svg" },
"values" => { "css_class" => "epilson" },
},
]
)
site.read
@staff = site.collections["staff"]
end
should "affect the appropriate items only" do
@staff.docs.each do |item|
assert_equal "simple", item.data["layout"]
assert_nil item.data["css_class"]
end
@staff.files.each do |item|
assert_equal "epilson", item.data["css_class"]
assert_nil item.data["layout"]
end
end end
end end