|
|
@ -8,7 +8,7 @@ let [
|
|
|
|
url,
|
|
|
|
url,
|
|
|
|
title = '',
|
|
|
|
title = '',
|
|
|
|
subtitle = '',
|
|
|
|
subtitle = '',
|
|
|
|
date = moment().format('YYYY-MM-DD')
|
|
|
|
date = moment().format('YYY-MM-DD')
|
|
|
|
] = process.argv.slice(2);
|
|
|
|
] = process.argv.slice(2);
|
|
|
|
|
|
|
|
|
|
|
|
const path = './pdf';
|
|
|
|
const path = './pdf';
|
|
|
@ -31,12 +31,8 @@ try{
|
|
|
|
|
|
|
|
|
|
|
|
// open page
|
|
|
|
// open page
|
|
|
|
const page = await browser.newPage();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
page.setDefaultNavigationTimeout(0);
|
|
|
|
await page.goto(url, { waitUntil: 'networkidle0' });
|
|
|
|
await page.goto(url);
|
|
|
|
console.log('page loaded');
|
|
|
|
await Promise.any([
|
|
|
|
|
|
|
|
page.mainFrame().waitForNavigation({waitUntil: 'networkidle0'}),
|
|
|
|
|
|
|
|
new Promise(resolve => setTimeout(resolve,2000))
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search for header and subheader in document
|
|
|
|
// search for header and subheader in document
|
|
|
|
if (!title) title = await (await page.waitForSelector('h1')).evaluate(el => el.textContent);
|
|
|
|
if (!title) title = await (await page.waitForSelector('h1')).evaluate(el => el.textContent);
|
|
|
@ -79,7 +75,7 @@ try{
|
|
|
|
width: 100%;
|
|
|
|
width: 100%;
|
|
|
|
padding: 2mm;
|
|
|
|
padding: 2mm;
|
|
|
|
border-bottom: 1px #222 solid;
|
|
|
|
border-bottom: 1px #222 solid;
|
|
|
|
">${[title, subtitle].map(el=>el.trim()).filter(el=>!!el).join(' - ')}</div>
|
|
|
|
">${[title, subtitle].map(el=>el.trim()).filter(el=>!!el).join(' | ')}</div>
|
|
|
|
`,
|
|
|
|
`,
|
|
|
|
footerTemplate: `
|
|
|
|
footerTemplate: `
|
|
|
|
<div style="
|
|
|
|
<div style="
|
|
|
|