Index frontmatter off source_file, allowing us to get rid of Resource#relative_path

This commit is contained in:
Ben Hollis 2012-04-29 18:51:00 -07:00
parent 23e0586896
commit dee0e616ad
2 changed files with 6 additions and 18 deletions

View file

@ -40,7 +40,7 @@ module Middleman::CoreExtensions::FrontMatter
# This page's frontmatter # This page's frontmatter
# @return [Hash] # @return [Hash]
def data def data
app.frontmatter(relative_path).first app.frontmatter(source_file).first
end end
end end
@ -65,10 +65,8 @@ module Middleman::CoreExtensions::FrontMatter
end end
sitemap.provides_metadata matcher do |path| sitemap.provides_metadata matcher do |path|
relative_path = path.sub(self.source_dir, "") fmdata = if self.frontmatter_extension.has_data?(path)
self.frontmatter(path)[0]
fmdata = if self.frontmatter_extension.has_data?(relative_path)
self.frontmatter(relative_path)[0]
else else
{} {}
end end
@ -155,11 +153,9 @@ module Middleman::CoreExtensions::FrontMatter
data, content = result data, content = result
data = ::Middleman::Util.recursively_enhance(data).freeze data = ::Middleman::Util.recursively_enhance(data).freeze
file = file.sub(@app.source_dir, "")
@local_data[file] = [data, content] @local_data[file] = [data, content]
path = File.join(@app.source_dir, file) @app.cache.set([:raw_template, file], result[1])
@app.cache.set([:raw_template, path], result[1]) @app.frontmatter_did_change(file)
@app.frontmatter_did_change(path)
end end
end end
@ -168,11 +164,9 @@ module Middleman::CoreExtensions::FrontMatter
# @return [void] # @return [void]
def remove_file(file) def remove_file(file)
file = File.expand_path(file, @app.root) file = File.expand_path(file, @app.root)
file = file.sub(@app.source_dir, "")
if @local_data.has_key?(file) if @local_data.has_key?(file)
path = File.join(@app.source_dir, file) @app.cache.remove(:raw_template, file)
@app.cache.remove(:raw_template, path)
@local_data.delete(file) @local_data.delete(file)
end end
end end

View file

@ -117,11 +117,5 @@ module Middleman::Sitemap
def url def url
'/' + destination_path.sub(/#{Regexp.escape(app.index_file)}$/, '') '/' + destination_path.sub(/#{Regexp.escape(app.index_file)}$/, '')
end end
# Get the relative path from the source
# @return [String]
def relative_path
source_file ? source_file.sub(app.source_dir, '') : nil
end
end end
end end