Adds default front-matter support for collecitons

This commit is contained in:
Jens Nazarenus 2014-05-16 00:04:31 +02:00
parent 7a9bc641ee
commit c8786b7b28
1 changed files with 10 additions and 1 deletions

View File

@ -176,6 +176,8 @@ module Jekyll
end end
# Read in the file and assign the content and data based on the file contents. # Read in the file and assign the content and data based on the file contents.
# Merge the frontmatter of the file with the frontmatter default
# values
# #
# Returns nothing. # Returns nothing.
def read(opts = {}) def read(opts = {})
@ -183,10 +185,17 @@ module Jekyll
@data = SafeYAML.load_file(path) @data = SafeYAML.load_file(path)
else else
begin begin
defaults = @site.frontmatter_defaults.all(path, collection.label.to_sym)
unless defaults.empty?
@data = defaults
end
@content = File.read(path, merged_file_read_opts(opts)) @content = File.read(path, merged_file_read_opts(opts))
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
@content = $POSTMATCH @content = $POSTMATCH
@data = SafeYAML.load($1) data_file = SafeYAML.load($1)
unless data_file.nil?
@data = Utils.deep_merge_hashes(defaults, data_file)
end
end end
rescue SyntaxError => e rescue SyntaxError => e
puts "YAML Exception reading #{path}: #{e.message}" puts "YAML Exception reading #{path}: #{e.message}"