<@UMR6GE8NQ> To save my sanity I made a script so ...
# advancedpdf
j
@makon To save my sanity I made a script so I can write my template without inline css and then use the script to produce a file that is the same template but with the css inlined.
Copy code
// 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');
});