add simple jekyll hook server

This commit is contained in:
encrypt 2015-02-20 02:50:13 +01:00
parent e1fcb0b24e
commit 9605f9b51a

33
jekyll/scripts/hook-server.rb Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env ruby
require 'sinatra'
require 'json'
require 'git'
require 'jekyll'
set :source, '/root/clones'
set :destination, '/srv/hosts'
def build_site(name, url)
puts settings.source
options = {
server: false,
auto: false,
source: File.join(settings.source, name),
destination: File.join(settings.destination, name),
plugins: File.join(settings.source, name, '_plugins')
}
unless Dir.exists?(options[:source])
Git.clone(url, 'test', path: settings.source)
else
g = Git.init(options[:source])
g.pull
end
site = Jekyll::Site.new(Jekyll.configuration(options))
site.process
end
post '/hooks/gogs/jekyll' do
request.body.rewind
data = JSON.parse(request.body.read)
build_site(data["repository"]["name"], data["repository"]["url"])
end