From 274c6d366700273874a05f893226c172992a0141 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Sat, 28 Jun 2014 18:33:16 -0700 Subject: [PATCH] Allow static files in collections Allow Documents to be static files so static files can exist in collections --- lib/jekyll/document.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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)