Sha256: 0d0d60f157d6433c758e8564d148fd5ec8cfd67f3072ab15a1854a2df1d21527

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

=begin
The MIT License

Copyright 2017 Carl Sampson <carl.sampson@gmail.com>.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=end

require 'jekyll-clicky/clicky'

CLICKY_CONFIG_KEY = "jekyll_clicky"

def inject_script(site)
  site.site.config[CLICKY_CONFIG_KEY].keys().each{ |a|
    begin
      id = site.site.config[CLICKY_CONFIG_KEY][a]["id"]
      clicky = Clicky.new id
      site.output = site.output.gsub(/(?=<\/body>)/i, clicky.code())
    rescue
      raise StandardError, "Unable to read clicky id"
    end

  }
end

#for pages and posts inject our code
Jekyll::Hooks.register :pages, :post_render do |page|
  inject_script(page)
end

Jekyll::Hooks.register :post, :post_render do |post|
  inject_script(post)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-clicky-0.1.1 lib/jekyll-clicky.rb
jekyll-clicky-0.1.0 lib/jekyll-clicky.rb