Last active
December 21, 2015 10:28
-
-
Save grabbeh/6291879 to your computer and use it in GitHub Desktop.
This file contains 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
var express = require('express') | |
, fs = require('fs') | |
, cheerio = require('cheerio') | |
, app = express(); | |
app.configure(function(){ | |
app.use(express.bodyParser()); | |
}); | |
app.post('/', function(req, res){ | |
var payload = req.body.payload; | |
var parsedResponse = JSON.parse(payload); | |
var title = parsedResponse.name; | |
var parsedhtml = parsedResponse.content_html; | |
fs.readFile('/usr/local/nginx/html/blog/template.html', function(err, data){ | |
$ = cheerio.load(data); | |
$('h3').text(title); | |
$('#textbody').html(parsedhtml); | |
var updatedhtml = $.html(); | |
fs.writeFile('/usr/local/nginx/html/blog/' + title + '.html', updatedhtml, function(err){ | |
if (!err) { | |
res.set('location', 'http://blog.grabeh.net/' + title); | |
res.send(); | |
} | |
}); | |
}) | |
}); | |
app.listen(3010); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment