Skip to content

Instantly share code, notes, and snippets.

@mloberg
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloberg/11165632 to your computer and use it in GitHub Desktop.
Save mloberg/11165632 to your computer and use it in GitHub Desktop.
guard-jekyll
require 'jekyll'
module ::Guard
class Jekyll < Guard
def start
puts "Starting Jekyll on port #{port}"
options = ::Jekyll.configuration({:serving => true, :watch => true, :port => port})
p = ::Process.fork do
::Jekyll::Commands::Build.process(options)
::Jekyll::Commands::Serve.process(options)
end
save_pid(p)
::Proccess.detach(p)
puts "Jekyll is running with pid #{p}"
end
def stop
if pid
puts "Sending INT signal to Jekyll (#{pid})"
::Process.kill("INT", pid)
true
end
end
def reload
stop
start
end
def run_all
true
end
def run_on_change(paths)
true
end
private
def save_pid(p)
File.open(pidfile_path, 'w') { |f| f.write(p) }
end
def pidfile_path
options.fetch(:pidfile) {
File.expand_path('tmp/jekyll.pid', File.dirname(__FILE__))
}
end
def pid
File.exist?(pidfile_path) && File.read(pidfile_path).to_i
end
def port
options.fetch(:port) { 4000 }
end
end
end
# Available options: :pidfile, :port
guard 'jekyll'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment