jkabot
01/16/2020, 4:54 PM// inline_css.js
/**
* Many email clients do not support embedded style sheets.
* Produce a version of each input template that has
* css applied as inline style attribute.
*
* node inline_css **\/*.ftl
*/
const fs = require('fs').promises;
const juice = require('juice');
// <https://github.com/Automattic/juice/issues/257#issuecomment-447036684>
Object.assign(juice.codeBlocks, {
freemarkerStart: {
start: '<#',
end: '>'
},
freemarkerEnd: {
start: '</#',
end: '>'
}
});
const juiceOptions = { xmlMode: true };
const outfile = (infileName) => {
const parts = infileName.split('.');
parts.splice(-1, 0, 'inline_css');
return parts.join('.');
};
const filepaths = process.argv.slice(2);
filepaths.forEach(async (infile) => {
if (infile.split('.').includes('inline_css')) {
return;
}
const html = await fs.readFile(infile, 'utf8');
const result = juice(html, juiceOptions);
return fs.writeFile(outfile(infile), result, 'utf8');
});