2015-10-25 21:21:46 +00:00
|
|
|
module Jekyll
|
|
|
|
class SeoTag < Liquid::Tag
|
|
|
|
|
|
|
|
attr_accessor :context
|
|
|
|
|
|
|
|
def render(context)
|
|
|
|
@context = context
|
2016-01-11 00:49:18 +00:00
|
|
|
output = template.render!(payload, info)
|
2015-11-25 21:23:59 +00:00
|
|
|
|
|
|
|
output
|
2015-10-25 21:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def payload
|
|
|
|
{
|
|
|
|
"page" => context.registers[:page],
|
|
|
|
"site" => context.registers[:site].site_payload["site"]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def info
|
|
|
|
{
|
|
|
|
:registers => context.registers,
|
|
|
|
:filters => [Jekyll::Filters]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-01-11 00:49:18 +00:00
|
|
|
def template
|
|
|
|
@template ||= Liquid::Template.parse template_contents
|
|
|
|
end
|
|
|
|
|
2015-10-25 21:21:46 +00:00
|
|
|
def template_contents
|
2016-01-06 20:29:14 +00:00
|
|
|
@template_contents ||= File.read(template_path).gsub(/(>\n|[%}]})\s+(<|{[{%])/,'\1\2').chomp
|
2015-10-25 21:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def template_path
|
|
|
|
@template_path ||= File.expand_path "./template.html", File.dirname(__FILE__)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Liquid::Template.register_tag('seo', Jekyll::SeoTag)
|