Allow static files in collections

Allow Documents to be static files so static files can exist in collections
This commit is contained in:
Alfred Xing 2014-06-28 18:33:16 -07:00
parent 7e2298b8d0
commit 274c6d3667
1 changed files with 10 additions and 3 deletions

View File

@ -80,12 +80,19 @@ module Jekyll
%w[.sass .scss .coffee].include?(extname) %w[.sass .scss .coffee].include?(extname)
end 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. # Determine whether the file should be rendered with Liquid.
# #
# Returns false if the document is either an asset file or a yaml file, # Returns false if the document is either an asset file or a yaml file,
# true otherwise. # true otherwise.
def render_with_liquid? def render_with_liquid?
!(asset_file? || yaml_file?) !(asset_file? || yaml_file?) && has_yaml_header?
end end
# Determine whether the file should be placed into layouts. # 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, # Returns false if the document is either an asset file or a yaml file,
# true otherwise. # true otherwise.
def place_in_layout? def place_in_layout?
!(asset_file? || yaml_file?) !(asset_file? || yaml_file?) && has_yaml_header?
end end
# The URL template where the document would be accessible. # The URL template where the document would be accessible.
@ -189,7 +196,7 @@ module Jekyll
unless defaults.empty? unless defaults.empty?
@data = defaults @data = defaults
end 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 if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
@content = $POSTMATCH @content = $POSTMATCH
data_file = SafeYAML.load($1) data_file = SafeYAML.load($1)