From c8786b7b281281bd127309b2a8fafea38c5d2cac Mon Sep 17 00:00:00 2001 From: Jens Nazarenus Date: Fri, 16 May 2014 00:04:31 +0200 Subject: [PATCH] Adds default front-matter support for collecitons --- lib/jekyll/document.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 0fb6719f..f4f70e18 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -176,6 +176,8 @@ module Jekyll end # 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. def read(opts = {}) @@ -183,10 +185,17 @@ module Jekyll @data = SafeYAML.load_file(path) else 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)) if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m @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 rescue SyntaxError => e puts "YAML Exception reading #{path}: #{e.message}"