2014-07-04 04:44:26 +02:00
|
|
|
ignore '*.frontmatter'
|
|
|
|
|
|
|
|
# Reads neighbor for every file on every refresh.
|
|
|
|
# TODO: Optimize
|
|
|
|
class NeighborFrontmatter < ::Middleman::Extension
|
|
|
|
self.resource_list_manipulator_priority = 81
|
|
|
|
|
|
|
|
def manipulate_resource_list(resources)
|
|
|
|
resources.each do |resource|
|
2015-09-09 20:55:56 +02:00
|
|
|
next unless resource.file_descriptor
|
2014-07-04 04:44:26 +02:00
|
|
|
|
2015-09-09 20:55:56 +02:00
|
|
|
neighbor = "#{resource.file_descriptor[:relative_path]}.frontmatter"
|
2014-07-16 03:01:45 +02:00
|
|
|
|
|
|
|
file = app.files.find(:source, neighbor)
|
|
|
|
|
|
|
|
next unless file
|
|
|
|
|
2015-10-23 11:08:09 +02:00
|
|
|
fmdata = ::Middleman::Util::Data.parse(file[:full_path], app.config[:frontmatter_delims], :yaml).first
|
2014-07-16 03:01:45 +02:00
|
|
|
opts = fmdata.extract!(:layout, :layout_engine, :renderer_options, :directory_index, :content_type)
|
|
|
|
opts[:renderer_options].symbolize_keys! if opts.key?(:renderer_options)
|
|
|
|
ignored = fmdata.delete(:ignored)
|
|
|
|
resource.add_metadata options: opts, page: fmdata
|
|
|
|
resource.ignore! if ignored == true && !resource.is_a?(::Middleman::Sitemap::ProxyResource)
|
2014-07-04 04:44:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Middleman::Extensions.register :neighbor_frontmatter, NeighborFrontmatter unless Middleman::Extensions.registered.include? :neighbor_frontmatter
|
|
|
|
|
|
|
|
activate :neighbor_frontmatter
|