Skip to content

Commit

Permalink
Add new options
Browse files Browse the repository at this point in the history
  • Loading branch information
davethegr8 committed Dec 15, 2020
1 parent cdaa914 commit e660ad0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Downloading Chromium r555668 - 76.4 Mb [====================] 100% 0.0s

Change the viewport width. Default is 1440, set to any value to change the page size.

`--height [height]`

Change the viewport height. Default is 1080, set to any value to change the page size.

`--resetHeight [true | false]`

After page load, reset the height of the viewport to the height of the page to capture all content on the page.

`--verbose true`

More info
Expand Down
30 changes: 27 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,43 @@ const defaults = {
verbose: false,
url: "http://example.com",
filename: null,
width: 1440
width: 1440,
height: 1080,
resetHeight: true,
help: false,
};

var args = Object.assign(defaults, minimist(process.argv.slice(2)));
args.verbose && console.log(args);

if (args.verbose) console.log(((new Date) - start) + 'ms', 'args', args);

if (args.help) {
const usage = `pixxy - a small utility to make an image of a webpage
Options:
--verbose: true | false Show more logs
--url: (required)
--filename Save to this file
--width: 1440
--height: 1080
--resetHeight
--help
`;

console.log(usage);

process.exit();
}

(async () => {
// todo save / show timing info

const browser = await puppeteer.launch();
const page = await browser.newPage();

// todo configurable width
let defaultViewport = { width: args.width, height: 1080 }
let defaultViewport = { width: args.width, height: args.height }
await page.setViewport(defaultViewport);

if (args.verbose) console.log(((new Date) - start) + 'ms', 'loading ' + args.url);
Expand All @@ -40,7 +62,9 @@ if (args.verbose) console.log(((new Date) - start) + 'ms', 'args', args);

defaultViewport.height = dimensions.height;

await page.setViewport(defaultViewport);
if (args.resetHeight) {
await page.setViewport(defaultViewport);
}

if (args.verbose) console.log(((new Date) - start) + 'ms', 'viewport:', defaultViewport);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixxy",
"version": "0.2.0",
"version": "0.3.0",
"repository": {
"type": "git",
"url": "https://github.com/davethegr8/pixxy.git"
Expand Down

0 comments on commit e660ad0

Please sign in to comment.