Make frontmatter always return a hash, and freeze it. This reduces the need for nil checks and prevents users from accidentally trying to modify frontmatter data which may be cached elsewhere.
This commit is contained in:
parent
c69fac9028
commit
92713dfe92
|
@ -139,7 +139,7 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
if result
|
if result
|
||||||
data, content = result
|
data, content = result
|
||||||
data = ::Middleman.recursively_enhance(data)
|
data = ::Middleman.recursively_enhance(data).freeze
|
||||||
file = file.sub(@app.source_dir, "")
|
file = file.sub(@app.source_dir, "")
|
||||||
@local_data[file] = [data, content]
|
@local_data[file] = [data, content]
|
||||||
path = File.join(@app.source_dir, file)
|
path = File.join(@app.source_dir, file)
|
||||||
|
@ -164,12 +164,12 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
# Get the frontmatter for a given path
|
# Get the frontmatter for a given path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Hash, nil]
|
# @return [Hash]
|
||||||
def data(path)
|
def data(path)
|
||||||
if @local_data.has_key?(path.to_s)
|
if @local_data.has_key?(path.to_s)
|
||||||
@local_data[path.to_s]
|
@local_data[path.to_s]
|
||||||
else
|
else
|
||||||
nil
|
{}.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -204,10 +204,9 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
# This page's frontmatter
|
# This page's frontmatter
|
||||||
# @return [Hash, nil]
|
# @return [Hash]
|
||||||
def data
|
def data
|
||||||
data, content = app.frontmatter(relative_path)
|
app.frontmatter(relative_path).first
|
||||||
data || nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This page's parent page
|
# This page's parent page
|
||||||
|
@ -216,7 +215,6 @@ module Middleman::Sitemap
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
if path.include?(app.index_file)
|
if path.include?(app.index_file)
|
||||||
parts.pop
|
parts.pop
|
||||||
else
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil if parts.length < 1
|
return nil if parts.length < 1
|
||||||
|
|
Loading…
Reference in a new issue