From d68909d16ae69b03cc94943af478b2c7d1b79363 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Fri, 6 Jan 2017 00:53:07 +0100 Subject: [PATCH] Add support for multiple configurations Allow using an array with multiple configurations in _config.yml. This allow to generate different archives with different layouts for the same type. For instance, this example would generate two different archives in different places: jekyll-archives: - layout: archive-html enabled: - tags permalinks: tag: "/tag/:name/" - layout: archive-rss enabled: - tags - categories permalinks: tag: "/feed/tag/:name/" category: "/feed/category/:name/" --- lib/jekyll-archives.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/jekyll-archives.rb b/lib/jekyll-archives.rb index 94e59a9..56ee470 100644 --- a/lib/jekyll-archives.rb +++ b/lib/jekyll-archives.rb @@ -30,10 +30,15 @@ class Archives < Jekyll::Generator } def initialize(config = nil) + @configs = [] if config['jekyll-archives'].nil? - @config = DEFAULTS + @configs << DEFAULTS + elsif config['jekyll-archives'].is_a? Array + config['jekyll-archives'].each do |c| + @configs << Utils.deep_merge_hashes(DEFAULTS, c) + end else - @config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives']) + @configs << Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives']) end end @@ -42,9 +47,12 @@ def generate(site) @posts = site.posts @archives = [] - @site.config['jekyll-archives'] = @config + @configs.each do |c| + @config = c + @site.config['jekyll-archives'] = @config + read + end - read @site.pages.concat(@archives) @site.config["archives"] = @archives