Skip to content

Instantly share code, notes, and snippets.

@wangzuo
Last active August 29, 2015 14:25
Show Gist options
  • Save wangzuo/d5bd8d620b22f4baaaa9 to your computer and use it in GitHub Desktop.
Save wangzuo/d5bd8d620b22f4baaaa9 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var mustache = require('mustache');
var onebox = require('onebox');
// custom render method for preview
var preview = onebox({
render: function(engine, data, cb) {
var tpath = path.join(__dirname, 'templates', engine+'.mustache');
fs.readFile(tpath, function(err, buf) {
if(err) return cb(err);
var template = buf.toString();
var html = mustache.render(template, data);
cb(null, html);
});
}
});
var link = 'http://github.com/wangzuo/onebox/issues/1';
preview(link, function(err, html) {
if(err) throw err;
console.log(html);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment