added fs-extra to have ensure-dir for non existing dirs

This commit is contained in:
2019-06-03 09:42:45 +02:00
parent aafa528f03
commit da5ed78558
9 changed files with 54 additions and 805 deletions
+10 -3
View File
@@ -7,7 +7,8 @@
*/
const puppeteer = require('puppeteer');
const fs = require("fs")
const fs_bare = require("fs") // required for fs-extra
const fs = require("fs-extra")
const path = require("path")
const start_dir = process.cwd()
const start_file = path.join(start_dir,"lib","index.html")
@@ -39,18 +40,24 @@ async function makeScreenshot(href){
page.once("load",logPageEvent)
await page.goto(href)
href = href.replace("file:///","")
const fname = path.parse(href).name
let fpath
if (fname != "index"){
image_url = href.replace(fname + ".html" ,"thumbnails/" + fname + ".png")
fpath = href.replace(fname + ".html", "thumbnails")
}
else{
image_url = href.replace(fname + ".html" ,"thumbnail.png")
fpath = href.replace(fname + ".html", "")
}
image_url = image_url.replace("file:///","")
// image_url = image_url.replace("file:///","")
// fpath = fpath.replace("file:///","")
page.removeAllListeners()
fs.ensureDir(fpath)
await page.screenshot({path: image_url});
await browser.close();
}