Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active January 25, 2019 23:51
Show Gist options
  • Save marksteve/8243318 to your computer and use it in GitHub Desktop.
Save marksteve/8243318 to your computer and use it in GitHub Desktop.
Push-to-deploy static sites with Pelican, Flask and Github
from __future__ import print_function
import os
from subprocess import check_output
from flask import abort, Flask, json, jsonify, request
app = Flask(__name__)
@app.route('/<secret>', methods=['POST'])
def post(secret):
if secret != os.environ['SECRET']:
abort(403)
payload = json.loads(request.form['payload'])
branch = payload.get('ref').split('/')[2]
cmd = 'pelican -d -o {root}/{branch} content'
print(check_output(cmd.format(
root=os.environ.get('ROOT', '/srv/pelican'),
branch=branch,
), shell=True))
return jsonify(dict(ok=True))
if __name__ == '__main__':
app.run(port=int(os.environ.get('PORT', 5000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment