diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index eb1c938..689e5b1 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -1,9 +1,11 @@ require "jekyll" require "jekyll-seo-tag/version" -require "jekyll-seo-tag/drop" module Jekyll class SeoTag < Liquid::Tag + autoload :Drop, "jekyll-seo-tag/drop" + autoload :Filters, "jekyll-seo-tag/filters" + attr_accessor :context # Matches all whitespace that follows either diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 3910407..a2f7714 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -2,12 +2,6 @@ module Jekyll class SeoTag class Drop < Jekyll::Drops::Drop TITLE_SEPARATOR = " | ".freeze - INCLUDES = [Jekyll::Filters, Liquid::StandardFilters].freeze - - INCLUDES.each do |klass| - include klass - klass.instance_methods.each { |method| private method } - end def initialize(text, context) @obj = {} @@ -129,9 +123,9 @@ module Jekyll @logo ||= begin return unless site["logo"] if absolute_url? site["logo"] - uri_escape site["logo"] + filters.uri_escape site["logo"] else - uri_escape absolute_url site["logo"] + filters.uri_escape filters.absolute_url site["logo"] end end end @@ -155,10 +149,10 @@ module Jekyll image["path"] ||= image["facebook"] || image["twitter"] unless absolute_url? image["path"] - image["path"] = absolute_url image["path"] + image["path"] = filters.absolute_url image["path"] end - image["path"] = uri_escape image["path"] + image["path"] = filters.uri_escape image["path"] @image = image.to_liquid end @@ -169,6 +163,10 @@ module Jekyll private + def filters + @filters ||= Jekyll::SeoTag::Filters.new(@context) + end + def page @page ||= @context.registers[:page].to_liquid end @@ -194,7 +192,7 @@ module Jekyll def format_string(string) methods = %i[markdownify strip_html normalize_whitespace escape_once] methods.each do |method| - string = send(method, string) + string = filters.public_send(method, string) end string unless string.empty? diff --git a/lib/jekyll-seo-tag/filters.rb b/lib/jekyll-seo-tag/filters.rb new file mode 100644 index 0000000..2874aed --- /dev/null +++ b/lib/jekyll-seo-tag/filters.rb @@ -0,0 +1,12 @@ +module Jekyll + class SeoTag + class Filters + include Jekyll::Filters + include Liquid::StandardFilters + + def initialize(context) + @context = context + end + end + end +end