mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-26 00:35:02 +03:00
Add export package
This commit is contained in:
parent
8ea8880fab
commit
17d1964959
@ -11,23 +11,21 @@ add a `build` script to your `package.json` file.
|
||||
}
|
||||
```
|
||||
|
||||
### PDF & Screenshots
|
||||
### PDF
|
||||
|
||||
Version 2 will support exporting to PDF or screenshot with a separate CLI.
|
||||
This has not been released yet.
|
||||
To export a deck as PDF, install the export CLI package:
|
||||
|
||||
<!-- TK
|
||||
## PDF Export
|
||||
|
||||
Presentations can be exported as PDF using the CLI.
|
||||
This works well as a backup option for any unforeseen technical difficulties.
|
||||
|
||||
```json
|
||||
"script": {
|
||||
"pdf": "mdx-deck pdf deck.mdx"
|
||||
}
|
||||
```sh
|
||||
npm i @mdx-deck/export
|
||||
```
|
||||
|
||||
Then run the following command to create a PDF:
|
||||
|
||||
```sh
|
||||
mdx-deck-export deck.mdx
|
||||
```
|
||||
|
||||
<!-- TK
|
||||
## Screenshots
|
||||
|
||||
A PNG image of the first slide can be exported with the `screenshot` command.
|
||||
|
1
packages/export/.gitignore
vendored
Normal file
1
packages/export/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist
|
20
packages/export/README.md
Normal file
20
packages/export/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# MDX Deck Export CLI
|
||||
|
||||
```sh
|
||||
npm i -D @mdx-deck/export
|
||||
```
|
||||
|
||||
```sh
|
||||
mdx-deck-export deck.mdx
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
```
|
||||
-d --out-dir Output directory
|
||||
-f --out-file Output filename
|
||||
-p --port Server port
|
||||
-w --width Width in pixels
|
||||
-h --height Height in pixels
|
||||
--no-sandbox Disable puppeteer sandbox
|
||||
```
|
80
packages/export/cli.js
Executable file
80
packages/export/cli.js
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
const path = require('path')
|
||||
const meow = require('meow')
|
||||
|
||||
const cli = meow(
|
||||
`
|
||||
|
||||
Usage:
|
||||
|
||||
$ mdx-deck-export deck.mdx
|
||||
|
||||
Options:
|
||||
|
||||
-d --out-dir Output directory
|
||||
-f --out-file Output filename
|
||||
-p --port Server port
|
||||
-w --width Width in pixels
|
||||
-h --height Height in pixels
|
||||
--no-sandbox Disable puppeteer sandbox
|
||||
|
||||
`,
|
||||
{
|
||||
flags: {
|
||||
outDir: {
|
||||
type: 'string',
|
||||
alias: 'd',
|
||||
default: 'dist',
|
||||
},
|
||||
outFile: {
|
||||
type: 'string',
|
||||
alias: 'f',
|
||||
default: 'presentation.pdf',
|
||||
},
|
||||
port: {
|
||||
type: 'string',
|
||||
alias: 'p',
|
||||
default: 8080,
|
||||
},
|
||||
width: {
|
||||
type: 'string',
|
||||
alias: 'w',
|
||||
default: 1280,
|
||||
},
|
||||
height: {
|
||||
type: 'string',
|
||||
alias: 'h',
|
||||
default: 960,
|
||||
},
|
||||
sandbox: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const [input] = cli.input
|
||||
|
||||
if (!input) {
|
||||
cli.showHelp(0)
|
||||
}
|
||||
|
||||
const opts = Object.assign({}, cli.flags, {
|
||||
input,
|
||||
dirname: path.dirname(path.resolve(input)),
|
||||
globals: {
|
||||
FILENAME: JSON.stringify(path.resolve(input)),
|
||||
},
|
||||
host: 'localhost',
|
||||
})
|
||||
|
||||
require('./index')(opts)
|
||||
.then(filename => {
|
||||
console.log('saved PDF to', filename)
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
process.exit(1)
|
||||
})
|
38
packages/export/index.js
Normal file
38
packages/export/index.js
Normal file
@ -0,0 +1,38 @@
|
||||
const path = require('path')
|
||||
const puppeteer = require('puppeteer')
|
||||
const mkdirp = require('mkdirp')
|
||||
const dev = require('mdx-deck/lib/dev')
|
||||
|
||||
module.exports = async opts => {
|
||||
const { outDir, outFile, port, width, height, sandbox } = opts
|
||||
|
||||
console.log(width, height)
|
||||
const args = []
|
||||
if (!sandbox) {
|
||||
args.push('--no-sandbox', '--disable-setuid-sandbox')
|
||||
}
|
||||
|
||||
const server = await dev(opts)
|
||||
|
||||
const browser = await puppeteer.launch({ args })
|
||||
const page = await browser.newPage()
|
||||
const filename = path.join(outDir, outFile)
|
||||
mkdirp.sync(outDir)
|
||||
|
||||
await page.goto(`http://localhost:${port}/print`, {
|
||||
waitUntil: 'networkidle2',
|
||||
})
|
||||
|
||||
await page.pdf({
|
||||
width,
|
||||
height,
|
||||
path: filename,
|
||||
scale: 1,
|
||||
printBackground: true,
|
||||
})
|
||||
|
||||
await browser.close()
|
||||
await server.close()
|
||||
|
||||
return filename
|
||||
}
|
19
packages/export/package.json
Normal file
19
packages/export/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@mdx-deck/export",
|
||||
"version": "2.0.0-0",
|
||||
"main": "index.js",
|
||||
"author": "Brent Jackson <jxnblk@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"mdx-deck-export": "./cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "./cli.js ../../docs/demo.mdx"
|
||||
},
|
||||
"dependencies": {
|
||||
"mdx-deck": "^2.0.0-0",
|
||||
"meow": "^5.0.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"puppeteer": "^1.13.0"
|
||||
}
|
||||
}
|
@ -29,17 +29,10 @@ const cli = meow(
|
||||
|
||||
${chalk.gray('Options')}
|
||||
|
||||
--webpack Path to webpack config file
|
||||
|
||||
${chalk.gray('Dev server options')}
|
||||
|
||||
-h --host Dev server host
|
||||
-p --port Dev server port
|
||||
--hot-port Dev server hot reload port
|
||||
--no-open Prevent from opening in default browser
|
||||
|
||||
${chalk.gray('Build options')}
|
||||
|
||||
--webpack Path to webpack config file
|
||||
-d --out-dir Output directory for exporting
|
||||
|
||||
`,
|
||||
|
@ -19,6 +19,9 @@ export default {
|
||||
'@media screen and (min-width:64em)': {
|
||||
fontSize: '48px',
|
||||
},
|
||||
'@media print': {
|
||||
fontSize: '40px',
|
||||
},
|
||||
'li > p': {
|
||||
margin: 0,
|
||||
},
|
||||
@ -32,7 +35,4 @@ export default {
|
||||
ul: {
|
||||
textAlign: 'left',
|
||||
},
|
||||
|
||||
// from v1
|
||||
// fontSizes: ['0.75em', '1em', '1.5em', '2em', '3em'],
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user