engine/lib/locomotive/liquid/tags/seo_metadata.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

2011-02-13 13:40:55 +00:00
module Locomotive
module Liquid
module Tags
class SEOMetadata < ::Liquid::Tag
def render(context)
%{
<meta name="description" content="#{sanitized_string(meta_description(context))}" />
<meta name="keywords" content="#{sanitized_string(meta_keywords(context))}" />
2011-02-13 13:40:55 +00:00
}
end
# Removes whitespace and quote charactets from the input
2011-02-13 13:40:55 +00:00
def sanitized_string(string)
string.strip.gsub(/"/, '')
end
def meta_description(context)
object = metadata_object(context)
object.try(:meta_description).blank? ? context.registers[:site].meta_description : object.meta_description
end
def meta_keywords(context)
object = metadata_object(context)
object.try(:meta_keywords).blank? ? context.registers[:site].meta_keywords : object.meta_keywords
end
def metadata_object(context)
context['content_instance'] || context['page']
end
2011-02-13 13:40:55 +00:00
end
::Liquid::Template.register_tag('seo_metadata', SEOMetadata)
end
end
end