Skip to content

Instantly share code, notes, and snippets.

@grabbeh
Last active December 21, 2015 10:28
Show Gist options
  • Save grabbeh/6291879 to your computer and use it in GitHub Desktop.
Save grabbeh/6291879 to your computer and use it in GitHub Desktop.
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