Skip to content

Commit

Permalink
Adds the --individual flag (danburzo#40)
Browse files Browse the repository at this point in the history
* --individual flag

* Add note about --individual usage

* Updates changelog
  • Loading branch information
danburzo authored Oct 15, 2018
1 parent 2aad093 commit e0e6650
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased

- Started separating the CLI from the Node library, working towards a programmatic API (Thank you, [@phenax](https://github.com/phenax)!)
- Adds `--individual` flag to export many pages as individual PDFs (https://github.com/danburzo/percollate/issues/38)

### 0.2.9

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The `pdf`, `epub`, and `html` commands have these options:
| Option | What it does |
| -------------- | -------------------------------------------------------------------------------------------------------------- |
| `-o, --output` | The path of the resulting bundle; when ommited, we derive the output file name from the title of the web page. |
| `--individual` | Export each web page as an individual file. |
| `--template` | Path to a custom HTML template |
| `--style` | Path to a custom CSS |
| `--css` | Additional CSS styles you can pass from the command-line to override the default/custom stylesheet styles |
Expand All @@ -92,6 +93,12 @@ You can use common Unix commands and keep the list of URLs in a newline-delimite
cat urls.txt | xargs percollate pdf --output some.pdf
```

To transform several web pages into individual PDF files at once, use the `--individual` flag:

```bash
percollate pdf --individual --output some.pdf https://example.com/page1 https://example.com/page2
```

### Custom page size / margins

The default page size is A5 (portrait). You can use the `--css` option to override it using [any supported CSS `size`](https://www.w3.org/TR/css3-page/#page-size):
Expand Down
3 changes: 2 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function with_common_options(cmd) {
.option('-o, --output [output]', 'Path for the generated bundle')
.option('--template [template]', 'Path to custom HTML template')
.option('--style [stylesheet]', 'Path to custom CSS')
.option('--css [style]', 'Additional CSS style');
.option('--css [style]', 'Additional CSS style')
.option('--individual', 'Export each web page as an individual file');
}

program.version(pkg.version);
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,16 @@ async function bundle(items, options) {
async function pdf(urls, options) {
let items = [];
for (let url of urls) {
items.push(await cleanup(url));
let item = await cleanup(url);
if (options.individual) {
await bundle([item], options);
} else {
items.push(item);
}
}
if (!options.individual) {
await bundle(items, options);
}
bundle(items, options);
}

/*
Expand Down

0 comments on commit e0e6650

Please sign in to comment.