add simple jekyll hook server
This commit is contained in:
parent
e1fcb0b24e
commit
9605f9b51a
1 changed files with 33 additions and 0 deletions
33
jekyll/scripts/hook-server.rb
Executable file
33
jekyll/scripts/hook-server.rb
Executable 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
|
Loading…
Reference in a new issue