From 76e062d734f0ad4d41dbc6df3904cb037cd14b1e Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 7 Oct 2020 21:21:32 +0530 Subject: [PATCH] Mutate hash literals instead of duplicating them (#417) Merge pull request 417 --- lib/jekyll-seo-tag/author_drop.rb | 2 +- lib/jekyll-seo-tag/image_drop.rb | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/jekyll-seo-tag/author_drop.rb b/lib/jekyll-seo-tag/author_drop.rb index b55cff0..2baa95e 100644 --- a/lib/jekyll-seo-tag/author_drop.rb +++ b/lib/jekyll-seo-tag/author_drop.rb @@ -78,7 +78,7 @@ module Jekyll if resolved_author.is_a? Hash resolved_author elsif resolved_author.is_a? String - { "name" => resolved_author }.merge(site_data_hash) + { "name" => resolved_author }.merge!(site_data_hash) else {} end diff --git a/lib/jekyll-seo-tag/image_drop.rb b/lib/jekyll-seo-tag/image_drop.rb index 32148ed..5427353 100644 --- a/lib/jekyll-seo-tag/image_drop.rb +++ b/lib/jekyll-seo-tag/image_drop.rb @@ -39,13 +39,17 @@ module Jekyll # The normalized image hash with a `path` key (which may be nil) def image_hash - @image_hash ||= if page["image"].is_a?(Hash) - { "path" => nil }.merge(page["image"]) - elsif page["image"].is_a?(String) - { "path" => page["image"] } - else - { "path" => nil } - end + @image_hash ||= begin + image_meta = page["image"] + + if image_meta.is_a?(Hash) + { "path" => nil }.merge!(image_meta) + elsif image_meta.is_a?(String) + { "path" => image_meta } + else + { "path" => nil } + end + end end alias_method :fallback_data, :image_hash