mirror of
https://github.com/wassname/template.git
synced 2026-06-27 19:17:15 +08:00
Fix render.js crash due to renamed inputs
This commit is contained in:
+9
-7
@@ -10,26 +10,28 @@ const transforms = require('../dist/transforms.v2.js');
|
||||
program
|
||||
.version('1.0.0')
|
||||
.description('Pre-renders distill articles for publication.')
|
||||
.usage('-i <input path> -o <output path>')
|
||||
.option('-i, --input_path <path>', 'path to input HTML file.')
|
||||
.option('-o, --output_path <path>', 'path to write rendered HTML file to.')
|
||||
.usage('-i <input_path> -o <output_path>')
|
||||
.option('-i, --input-path <path>', 'path to input HTML file.')
|
||||
.option('-o, --output-path <path>', 'path to write rendered HTML file to.')
|
||||
.parse(process.argv);
|
||||
|
||||
console.warn(program);
|
||||
|
||||
const virtualConsole = new jsdom.VirtualConsole();
|
||||
// omitJSDOMErrors as JSDOM routinely can't parse modern CSS
|
||||
virtualConsole.sendTo(console, { omitJSDOMErrors: true });
|
||||
|
||||
const options = { runScripts: 'outside-only', QuerySelector: true, virtualConsole: virtualConsole };
|
||||
JSDOM.fromFile(program.input, options).then(dom => {
|
||||
JSDOM.fromFile(program.inputPath, options).then(dom => {
|
||||
const window = dom.window;
|
||||
const document = window.document;
|
||||
|
||||
const data = new transforms.FrontMatter;
|
||||
data.inputHTMLPath = program.input; // may be needed to resolve relative links!
|
||||
data.inputDirectory = path.dirname(program.input);
|
||||
data.inputHTMLPath = program.inputPath; // may be needed to resolve relative links!
|
||||
data.inputDirectory = path.dirname(program.inputPath);
|
||||
transforms.render(document, data);
|
||||
transforms.distillify(document, data);
|
||||
|
||||
const transformedHtml = dom.serialize();
|
||||
fs.writeFileSync(program.output, transformedHtml);
|
||||
fs.writeFileSync(program.outputPath, transformedHtml);
|
||||
}).catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user