Sha256: dcfbd9e56fe110b548050b1260fadf46e2486b9b8026553e509c905b678c0994

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

module Jekyll
  class SeoTag < Liquid::Tag

    attr_accessor :context

    def render(context)
      @context = context
      output = Liquid::Template.parse(template_contents).render!(payload, info)

      # Minify
      output.gsub!(/[\s]{2,}/, "\n")

      # Encode smart quotes. See https://github.com/benbalter/jekyll-seo-tag/pull/6
      output.gsub!("\u201c", "&ldquo;")
      output.gsub!("\u201d", "&rdquo;")

      output
    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

    def template_contents
      @template_contents ||= File.read(template_path)
    end

    def template_path
      @template_path ||= File.expand_path "./template.html", File.dirname(__FILE__)
    end
  end
end

Liquid::Template.register_tag('seo', Jekyll::SeoTag)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-seo-tag-0.1.3 lib/jekyll-seo-tag.rb