Files
inline-html/lib/index.js

30 lines
712 B
JavaScript
Raw Normal View History

2015-07-23 08:28:22 -07:00
var _ = require('lodash');
2015-07-22 15:51:14 -07:00
var co = require('co');
var cheerio = require('cheerio');
var fs = require('mz/fs');
2015-07-23 08:28:22 -07:00
var inlineCss = require('./inline-css');
var inlineImg = require('./inline-img');
var inlineLinkLess = require('./inline-link-less');
2015-07-22 15:51:14 -07:00
2015-07-23 08:28:22 -07:00
var inline = co.wrap(function * (filename, options) {
options = _.defaults(options || {}, {
less: {}
2015-07-22 15:51:14 -07:00
});
2015-07-23 08:28:22 -07:00
var html = yield fs.readFile(filename, 'utf8');
2015-07-22 15:51:14 -07:00
2015-07-23 08:28:22 -07:00
// Inline links
html = yield inlineLinkLess(html, filename, options.less);
2015-07-22 15:51:14 -07:00
// TODO inline links: css
2015-07-23 08:28:22 -07:00
// TODO inline scripts
// browserify js? => scriptify
// Inline paths -> datauris
html = inlineCss(html, filename);
html = inlineImg(html, filename);
2015-07-22 15:51:14 -07:00
return html;
});
2015-07-23 08:28:22 -07:00
2015-07-22 15:51:14 -07:00
module.exports = inline;