diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 0c6b3296..20f4ecf6 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -35,6 +35,8 @@ module Middleman::Sitemap @source_file = source_file @destination_paths = [@path] + + @local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] } end # Whether this resource has a template file @@ -47,9 +49,34 @@ module Middleman::Sitemap # Get the metadata for both the current source_file and the current path # @return [Hash] def metadata - store.metadata_for_file(source_file).deep_merge( - store.metadata_for_path(path) - ) + result = store.metadata_for_file(source_file).dup + + path_meta = store.metadata_for_path(path).dup + if path_meta.has_key?(:blocks) + result[:blocks] << path_meta[:blocks] + path_meta.delete(:blocks) + end + result.deep_merge!(path_meta) + + local_meta = @local_metadata.dup + if local_meta.has_key?(:blocks) + result[:blocks] << local_meta[:blocks] + local_meta.delete(:blocks) + end + result.deep_merge!(local_meta) + + result + end + + # Merge in new metadata specific to this resource. + # @param [Hash] metadata A metadata block like provides_metadata_for_path takes + def add_metadata(metadata={}, &block) + if metadata.has_key?(:blocks) + @local_metadata[:blocks] << metadata[:blocks] + metadata.delete(:blocks) + end + @local_metadata.deep_merge(metadata) + @local_metadata[:blocks] << block if block_given? end # Get the output/preview URL for this resource diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index d64015a4..da6ec861 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -101,6 +101,12 @@ module Middleman::Sitemap next result if !matcher.nil? && !source_file.match(matcher) metadata = callback.call(source_file) + + if metadata.has_key?(:blocks) + result[:blocks] << metadata[:blocks] + metadata.delete(:blocks) + end + result.deep_merge(metadata) end end