added fs-extra to have ensure-dir for non existing dirs
@ -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();
|
||||
}
|
||||
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 184 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 103 KiB |
845
package-lock.json
generated
@ -28,6 +28,7 @@
|
||||
"gulp-uglify": "^3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": "^8.0.1",
|
||||
"gsap": "^2.1.3",
|
||||
"hammerjs": "^2.0.8",
|
||||
"optimal-select": "^4.0.1",
|
||||
|