Skip to content

Commit 0cf8533

Browse files
authored
Optimize default front matter using File.fnmatch? (#9185)
Merge pull request 9185
1 parent ee29b05 commit 0cf8533

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

lib/jekyll/frontmatter_defaults.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def applies_path?(scope, path)
109109
sanitized_path = sanitize_path(path)
110110

111111
if rel_scope_path.include?("*")
112-
glob_scope(sanitized_path, rel_scope_path)
112+
File.fnmatch?(strip_collections_dir(rel_scope_path), sanitized_path)
113113
else
114114
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
115115
end
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
speciality: Ruby
3+
---
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
speciality: JS Frameworks
3+
---

test/test_front_matter_defaults.rb

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class TestFrontMatterDefaults < JekyllUnitTest
2525
assert_equal "val", @affected.data["key"]
2626
assert_nil @not_affected.data["key"]
2727
end
28-
29-
should "not call Dir.glob block" do
30-
refute_includes @output, "Globbed Scope Path:"
31-
end
3228
end
3329

3430
context "A site with full front matter defaults (glob)" do
@@ -53,9 +49,38 @@ class TestFrontMatterDefaults < JekyllUnitTest
5349
assert_equal "val", @affected.data["key"]
5450
assert_nil @not_affected.data["key"]
5551
end
52+
end
53+
54+
context "A site with collections and front matter defaults with glob patterns" do
55+
setup do
56+
site = fixture_site(
57+
"collections_dir" => "gathering",
58+
"collections" => { "staff" => { "output" => true } },
59+
"defaults" => [
60+
{
61+
"scope" => { "path" => "_staff/**/*.md", "type" => "staff" },
62+
"values" => { "layout" => "simple" },
63+
},
64+
{
65+
"scope" => { "path" => "_staff/**/*.svg" },
66+
"values" => { "css_class" => "epilson" },
67+
},
68+
]
69+
)
70+
site.read
71+
@staff = site.collections["staff"]
72+
end
73+
74+
should "affect the appropriate items only" do
75+
@staff.docs.each do |item|
76+
assert_equal "simple", item.data["layout"]
77+
assert_nil item.data["css_class"]
78+
end
5679

57-
should "call Dir.glob block" do
58-
assert_includes @output, "Globbed Scope Path:"
80+
@staff.files.each do |item|
81+
assert_equal "epilson", item.data["css_class"]
82+
assert_nil item.data["layout"]
83+
end
5984
end
6085
end
6186

0 commit comments

Comments
 (0)