Last active
January 25, 2019 23:51
-
-
Save marksteve/8243318 to your computer and use it in GitHub Desktop.
Push-to-deploy static sites with Pelican, Flask and Github
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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