Merge pull request #409 from bhollis/metadata
Add Resource#add_metadata for attaching metadata directly to a resource
This commit is contained in:
commit
3d129b8523
|
@ -35,6 +35,8 @@ module Middleman::Sitemap
|
||||||
@source_file = source_file
|
@source_file = source_file
|
||||||
|
|
||||||
@destination_paths = [@path]
|
@destination_paths = [@path]
|
||||||
|
|
||||||
|
@local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this resource has a template file
|
# 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
|
# Get the metadata for both the current source_file and the current path
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def metadata
|
def metadata
|
||||||
store.metadata_for_file(source_file).deep_merge(
|
result = store.metadata_for_file(source_file).dup
|
||||||
store.metadata_for_path(path)
|
|
||||||
)
|
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
|
end
|
||||||
|
|
||||||
# Get the output/preview URL for this resource
|
# Get the output/preview URL for this resource
|
||||||
|
|
|
@ -101,6 +101,12 @@ module Middleman::Sitemap
|
||||||
next result if !matcher.nil? && !source_file.match(matcher)
|
next result if !matcher.nil? && !source_file.match(matcher)
|
||||||
|
|
||||||
metadata = callback.call(source_file)
|
metadata = callback.call(source_file)
|
||||||
|
|
||||||
|
if metadata.has_key?(:blocks)
|
||||||
|
result[:blocks] << metadata[:blocks]
|
||||||
|
metadata.delete(:blocks)
|
||||||
|
end
|
||||||
|
|
||||||
result.deep_merge(metadata)
|
result.deep_merge(metadata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue