diff --git a/jekyll-feed.gemspec b/jekyll-feed.gemspec index 27c45d71..1f4b6610 100644 --- a/jekyll-feed.gemspec +++ b/jekyll-feed.gemspec @@ -25,6 +25,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "nokogiri", "~> 1.6" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rubocop", "~> 0.57.2" + spec.add_development_dependency "rubocop", "~> 0.57.2" spec.add_development_dependency "typhoeus", ">= 0.7", "< 2.0" end diff --git a/lib/jekyll-feed/generator.rb b/lib/jekyll-feed/generator.rb index df0326e4..120ad2ea 100644 --- a/lib/jekyll-feed/generator.rb +++ b/lib/jekyll-feed/generator.rb @@ -28,7 +28,7 @@ def generate(site) # Returns the plugin's config or an empty hash if not set def config - @site.config["feed"] || {} + @config ||= @site.config["feed"] || {} end # Determines the destination path of a given feed @@ -42,13 +42,9 @@ def config # Will return `/feed/collection/category.xml` for other collection categories def feed_path(collection: "posts", category: nil) prefix = collection == "posts" ? "/feed" : "/feed/#{collection}" - if category - "#{prefix}/#{category}.xml" - elsif collections[collection] && collections[collection]["path"] - collections[collection]["path"] - else - "#{prefix}.xml" - end + return "#{prefix}/#{category}.xml" if category + + collections.dig(collection, "path") || "#{prefix}.xml" end # Returns a hash representing all collections to be processed and their metadata @@ -65,7 +61,7 @@ def collections end @collections = normalize_posts_meta(@collections) - @collections.each do |_name, meta| + @collections.each_value do |meta| meta["categories"] = (meta["categories"] || []).to_set end @@ -89,17 +85,17 @@ def file_exists?(file_path) # Generates contents for a file def make_page(file_path, collection: "posts", category: nil) - file = PageWithoutAFile.new(@site, __dir__, "", file_path) - file.content = feed_template - file.data.merge!({ - "layout" => nil, - "sitemap" => false, - "xsl" => file_exists?("feed.xslt.xml"), - "collection" => collection, - "category" => category, - }) - file.output - file + PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file| + file.content = feed_template + file.data.merge!( + "layout" => nil, + "sitemap" => false, + "xsl" => file_exists?("feed.xslt.xml"), + "collection" => collection, + "category" => category + ) + file.output + end end # Special case the "posts" collection, which, for ease of use and backwards diff --git a/lib/jekyll-feed/meta-tag.rb b/lib/jekyll-feed/meta-tag.rb index a06f415c..76da23f0 100644 --- a/lib/jekyll-feed/meta-tag.rb +++ b/lib/jekyll-feed/meta-tag.rb @@ -14,7 +14,7 @@ def render(context) private def config - @context.registers[:site].config + @config ||= @context.registers[:site].config end def attributes @@ -27,11 +27,7 @@ def attributes end def path - if config["feed"] && config["feed"]["path"] - config["feed"]["path"] - else - "feed.xml" - end + config.dig("feed", "path") || "feed.xml" end def title