diff --git a/lib/jekyll-feed/meta-tag.rb b/lib/jekyll-feed/meta-tag.rb index 54759297..d143c728 100644 --- a/lib/jekyll-feed/meta-tag.rb +++ b/lib/jekyll-feed/meta-tag.rb @@ -6,35 +6,22 @@ class MetaTag < Liquid::Tag include Jekyll::Filters::URLFilters def render(context) + # Jekyll::Filters::URLFilters requires `@context` to be set in the environment. @context = context - attrs = attributes.map do |k, v| - v = v.to_s unless v.respond_to?(:encode) - %(#{k}=#{v.encode(:xml => :attr)}) - end - "" - end - - private - - def config - @config ||= @context.registers[:site].config - end - def attributes - { - :type => "application/atom+xml", - :rel => "alternate", - :href => absolute_url(path), - :title => title, - }.keep_if { |_, v| v } - end + config = context.registers[:site].config + path = config.dig("feed", "path") || "feed.xml" + title = config["title"] || config["name"] - def path - config.dig("feed", "path") || "feed.xml" - end + attributes = { + :type => "application/atom+xml", + :rel => "alternate", + :href => absolute_url(path), + } + attributes[:title] = title if title - def title - config["title"] || config["name"] + attrs = attributes.map { |k, v| "#{k}=#{v.to_s.encode(:xml => :attr)}" }.join(" ") + "" end end end