diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 85b22ba5..bd812c2a 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -80,12 +80,19 @@ module Jekyll %w[.sass .scss .coffee].include?(extname) end + # Determine whether the document has a YAML header. + # + # Returns true if the file starts with three dashes + def has_yaml_header? + !!(File.open(path, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/) + end + # Determine whether the file should be rendered with Liquid. # # Returns false if the document is either an asset file or a yaml file, # true otherwise. def render_with_liquid? - !(asset_file? || yaml_file?) + !(asset_file? || yaml_file?) && has_yaml_header? end # Determine whether the file should be placed into layouts. @@ -93,7 +100,7 @@ module Jekyll # Returns false if the document is either an asset file or a yaml file, # true otherwise. def place_in_layout? - !(asset_file? || yaml_file?) + !(asset_file? || yaml_file?) && has_yaml_header? end # The URL template where the document would be accessible. @@ -189,7 +196,7 @@ module Jekyll unless defaults.empty? @data = defaults end - @content = File.read(path, merged_file_read_opts(opts)) + @content = File.open(path, "rb") { |f| f.read } if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m @content = $POSTMATCH data_file = SafeYAML.load($1)