diff --git a/bridgetown-core/lib/bridgetown-core/front_matter/defaults.rb b/bridgetown-core/lib/bridgetown-core/front_matter/defaults.rb index ced13ceea..139419045 100644 --- a/bridgetown-core/lib/bridgetown-core/front_matter/defaults.rb +++ b/bridgetown-core/lib/bridgetown-core/front_matter/defaults.rb @@ -5,6 +5,8 @@ module FrontMatter # This class handles custom defaults for front matter settings. # It is exposed via the frontmatter_defaults method on the site class. class Defaults + using Bridgetown::Refinements + # @return [Bridgetown::Site] attr_reader :site @@ -16,6 +18,7 @@ def initialize(site) def reset @glob_cache = {} @defaults_cache = {} + @sets = nil end def ensure_time!(set) @@ -175,15 +178,12 @@ def matching_sets(path, collection) # Returns a list of valid sets # - # This is not cached to allow plugins to modify the configuration - # and have their changes take effect - # # @return [Array] def valid_sets - sets = site.config["defaults"] - return [] unless sets.is_a?(Array) + @sets ||= site.config["defaults"].map(&:as_dots) + return [] unless @sets.is_a?(Array) - sets.filter_map do |set| + @sets.filter_map do |set| if valid?(set) massage_scope!(set) # TODO: is this trip really necessary? diff --git a/bridgetown-core/test/test_front_matter_defaults.rb b/bridgetown-core/test/test_front_matter_defaults.rb index d83e4e4c4..8eee78dbc 100644 --- a/bridgetown-core/test/test_front_matter_defaults.rb +++ b/bridgetown-core/test/test_front_matter_defaults.rb @@ -137,22 +137,22 @@ class TestFrontMatterDefaults < BridgetownUnitTest context "A site with front matter defaults with no path" do setup do - @site = fixture_site( - "defaults" => [{ - "scope" => { - "type" => "pages", - }, - "values" => { - "key" => "val", - }, - }] - ) - @site.process + @site = fixture_site + @site.config.defaults << { + scope: { + type: "pages", + }, + values: { + key: "val", + }, + } + @site.read @affected = @site.collections.pages.resources @not_affected = @site.collections.posts.resources end should "affect only the specified type and all paths" do + assert @affected.length > 1 assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, @not_affected