Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// it runs after the existing scripts on the page and therefore doesn't
// allow to modify things prior to their invocation.
const tmpPath = path.join(
path.dirname(example.path),
".tmp.example.screenshot." + path.basename(example.path)
);
const screenshotPage = cheerio.load(example.html);
screenshotPage("head").prepend(
cheerio("
], ({url, episode}) => {
const dest = path.resolve(userHome, 'Desktop')
const urlToScreenshot = `${url}/?feature-show=${episode.date}`
console.log(`Taking a screenshot of ${urlToScreenshot}`)
new Pageres({delay: 2})
.src(urlToScreenshot, ['1200x600'], {crop: true})
.dest(dest)
.run()
.then(() => {
console.log(`Screenshot saved: \n${dest}`)
})
.catch(err => {
console.error(`Problems saving screenshot: \n${err}`)
})
})
glob.sync('public/blog/*/index.html').forEach((file: string) => {
const pageres = new Pageres({
crop: true,
filename: 'post-screenshot',
delay: 2,
scale: 2,
css: `
.headroom-wrapper { display: none }
#content { max-width: 48rem }
`,
format: 'jpg',
});
pageres
.src(file, ['1200x630'])
.dest(path.dirname(file))
.run((err: ?Error) => {
if (err) {
function takeScreenshot(url, dest) {
return new Pageres({filename: 'screenshot'})
.src(url, ['1200x600'], {crop: true})
.dest(dest)
.run()
}
.then(chunks => chunks.reduce((p, chunk, i) => p.then(() => d(`reducing chunk ${i+1}/${chunks.length}, len=${chunk.length}`, chunk)
.reduce((ctx, source) =>
d(`adding pageres src ${source}, sizes=${sizes}`, ctx.src(source, sizes)),
d('creating pageres instance', new Pageres(prOpts))
)
.dest(screenshots)
.run()
.then(streams => d(`renaming streams, len=${streams.length}`, Promise.all(
streams.map(stream => d(`renaming ${stream.filename}`, prename(
join(screenshots, stream.filename),
join(screenshots, stream.filename
.replace(`${pages.replace(rsep, '!')}!`, '')
.replace(/\.html(-[\dx]+)[\w-]*\.png$/, '$1.html.png')
)
)))
)))
.catch(reason => d(`ERR! ${reason}`))
), d(`shot chunk reducer, len=${chunks.length}`, Promise.resolve())))