From 5672ec39916811960c71d47eaf4b292f09b26d02 Mon Sep 17 00:00:00 2001 From: Pat Hawks Date: Sun, 10 Jan 2016 16:49:18 -0800 Subject: [PATCH] Only process Liquid template once --- lib/jekyll-seo-tag.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index 5fb9800..9f6313f 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -11,7 +11,7 @@ module Jekyll def render(context) @context = context - output = Liquid::Template.parse(template_contents).render!(payload, info) + output = template.render!(payload, info) # Encode smart quotes. See https://github.com/benbalter/jekyll-seo-tag/pull/6 output.gsub!(HTML_ESCAPE_REGEX, HTML_ESCAPE) @@ -35,6 +35,10 @@ module Jekyll } end + def template + @template ||= Liquid::Template.parse template_contents + end + def template_contents @template_contents ||= File.read(template_path).gsub(/(>\n|[%}]})\s+(<|{[{%])/,'\1\2').chomp end