diff --git a/lib/jekyll-archives/page_drop.rb b/lib/jekyll-archives/page_drop.rb index b7a9cf1..f5e920b 100644 --- a/lib/jekyll-archives/page_drop.rb +++ b/lib/jekyll-archives/page_drop.rb @@ -7,8 +7,16 @@ class PageDrop < Jekyll::Drops::Drop mutable false - def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink - private def_delegator :@obj, :data, :fallback_data + def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink, + :site, :relative_path, :data + + def fallback_data + Jekyll::Utils.deep_merge_hashes( + data, site.frontmatter_defaults.all(relative_path, type) + ) + end + + private :site, :relative_path, :data, :fallback_data end end end diff --git a/test/test_jekyll_archive.rb b/test/test_jekyll_archive.rb index e38b51d..6ee6f8b 100644 --- a/test/test_jekyll_archive.rb +++ b/test/test_jekyll_archive.rb @@ -95,4 +95,75 @@ class TestJekyllArchive < Minitest::Test assert_equal expected, archive.to_liquid.to_h end end + + context "the generated archive page preconfigured with front matter defaults" do + setup do + site = fixture_site( + "jekyll-archives" => { + "enabled" => true, + }, + "defaults" => [ + { + "scope" => { + "type" => "category", + }, + "values" => { + "author_profile" => true, + "sidebar" => false, + }, + }, + { + "scope" => { + "type" => "day", + }, + "values" => { + "author_profile" => false, + "sidebar" => true, + }, + }, + ] + ) + site.read + Jekyll::Archives::Archives.new(site.config).generate(site) + @archives = site.config["archives"] + end + + should "expose all attributes to Liquid templates" do + archive = @archives.find { |a| a.type == "category" } + archive.posts = [] + expected = { + "author_profile" => true, + "sidebar" => false, + "layout" => "archive", + "posts" => [], + "type" => "category", + "title" => "plugins", + "date" => nil, + "name" => "index", + "path" => "category/plugins/index.html", + "url" => "/category/plugins/", + "permalink" => nil, + } + + assert_equal expected, archive.to_liquid.to_h + + archive = @archives.find { |a| a.type == "day" } + archive.posts = [] + expected = { + "author_profile" => false, + "sidebar" => true, + "layout" => "archive", + "posts" => [], + "type" => "day", + "title" => nil, + "date" => archive.date, + "name" => "index", + "path" => "2013/08/16/index.html", + "url" => "/2013/08/16/", + "permalink" => nil, + } + + assert_equal expected, archive.to_liquid.to_h + end + end end