Sha256: b527906d758b2f91e83c85ba3bd27b244bbce7c53f7335ed72efc2c63302a631

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'json'

# Register Hooks, if livereload is enabled
module Jekyll
  module Livereload
    module Build
      def process(opts)
        opts['host'] = 'localhost' unless opts.key?('host')
        opts['reload_port'] = Livereload::LIVERELOAD_PORT unless opts.key?('reload_port')
        if opts['livereload']
          Jekyll::Hooks.register(:site, :post_render) do |site|
            regenerator = Jekyll::Regenerator.new(site)
            Livereload.pages = site.pages.select do |p|
              regenerator.regenerate?(p)
            end
          end
          Jekyll::Hooks.register([:pages, :documents], :post_render) do |doc|
            doc.output.sub!(/<head>(.*)<\/head>/m, "<head>\\1#{reload_script(opts)}</head>")
          end
          Jekyll::Hooks.register :site, :post_write do
            Livereload.reactor.reload() unless Livereload.reactor.nil?
          end
        end

        super opts
      end

      private
      def reload_script(opts)
        "<script src=\"http://#{opts['host']}:#{opts['reload_port']}/livereload.js\"></script>"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-livereload-0.1.0 lib/jekyll-livereload/build.rb