Cache information about document YAML header existence

This commit is contained in:
Alfred Xing 2014-08-01 21:12:02 -07:00
parent a902fefed5
commit 5fdf637c6a
1 changed files with 3 additions and 1 deletions

View File

@ -15,6 +15,7 @@ module Jekyll
@site = relations[:site] @site = relations[:site]
@path = path @path = path
@collection = relations[:collection] @collection = relations[:collection]
@has_yaml_header = nil
end end
# Fetch the Document's data. # Fetch the Document's data.
@ -84,7 +85,8 @@ module Jekyll
# #
# Returns true if the file starts with three dashes # Returns true if the file starts with three dashes
def has_yaml_header? def has_yaml_header?
!!(File.open(path, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/) @has_yaml_header unless @has_yaml_header.nil?
@has_yaml_header = !!(File.open(path, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
end end
# Determine whether the file should be rendered with Liquid. # Determine whether the file should be rendered with Liquid.