From 5fdf637c6abbc65b52eeb9d55bc682cff1382515 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Fri, 1 Aug 2014 21:12:02 -0700 Subject: [PATCH] Cache information about document YAML header existence --- lib/jekyll/document.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index bd812c2a..1d6bf7d7 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -15,6 +15,7 @@ module Jekyll @site = relations[:site] @path = path @collection = relations[:collection] + @has_yaml_header = nil end # Fetch the Document's data. @@ -84,7 +85,8 @@ module Jekyll # # Returns true if the file starts with three dashes 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 # Determine whether the file should be rendered with Liquid.