Skip to content

Commit

Permalink
feat: cli allowDownload
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 28, 2021
1 parent dd4f963 commit 73fcba2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 47 deletions.
12 changes: 10 additions & 2 deletions docs/guide/exporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Exporting your slides into PDF by the following command

```bash
$ npm i -D playwright-chromium
$ slidev export
```

Expand All @@ -28,10 +29,17 @@ $ slidev build

The dist will be available under `dist/` and then you can host them on [GitHub Pages](https://pages.github.com/), [Netlify](https://netlify.app/), [Vercel](https://vercel.com/), or whatever you want. And share your slides with the world with a single link.

By default, it also generates a pdf file along with the build. And in the SPA, there will be a button for viewers to download the slides as PDF. If you don't want that, you can disable it by:
### Provide Downloadable PDF

You can provide a downloadable PDF to the viewers of your SPA. You can enable it by the following config:

```md
---
allow-download: false
allow-download: true
---
```

It will generate a pdf file along with the build. And a download button will appear in the SPA.

If you are building it in a CI environment, you might need to have [`playwright-chromium`](https://playwright.dev/docs/installation#download-single-browser-binary) installed as well. Learn more [here](https://playwright.dev/docs/ci)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"esno": "^0.5.0",
"execa": "^5.0.0",
"jest": "^26.6.3",
"playwright": "^1.10.0",
"playwright-chromium": "^1.10.0",
"pnpm": "^6.2.2",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4",
Expand Down
12 changes: 9 additions & 3 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ cli.command(
type: 'string',
describe: 'output base',
})
.option('allowDownload', {
alias: 'd',
type: 'boolean',
describe: 'allow download as PDF',
})
.help(),
async({ entry, theme, watch, base }) => {
console.log(yellow(' [Slidev] the SPA build is experimental, recommend to use dev server instead at this moment.'))

async({ entry, theme, watch, base, allowDownload }) => {
const options = await resolveOptions({ entry, theme }, 'build')
if (allowDownload)
options.data.config.allowDownload = allowDownload

printInfo(options)
await build(options, {}, {
base,
Expand Down
6 changes: 5 additions & 1 deletion packages/slidev/node/export.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import path from 'path'
import fs from 'fs-extra'
import { chromium } from 'playwright'
import { chromium } from 'playwright-chromium'
import { PDFDocument } from 'pdf-lib'
import { blue, cyan, green, yellow } from 'kolorist'
import { Presets, SingleBar } from 'cli-progress'
import { getPagesByRange } from './utils'
import { packageExists } from './themes'

export interface ExportOptions {
total: number
Expand Down Expand Up @@ -59,6 +60,9 @@ export async function exportSlides({
output = 'slides',
timeout = 500,
}: ExportOptions) {
if (!packageExists('playwright-chromium'))
throw new Error('The exporting for Slidev is powered by Playwright, please installed it via `npm i playwright-chromium`')

const browser = await chromium.launch()
const context = await browser.newContext({
viewport: {
Expand Down
6 changes: 3 additions & 3 deletions packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"homepage": "https://github.com/slidevjs/slidev",
"bugs": "https://github.com/slidevjs/slidev/issues",
"peerDependencies": {
"playwright": "^1.10.0"
"playwright-chromium": "^1.10.0"
},
"peerDependenciesMeta": {
"playwright": {
"playwright-chromium": {
"optional": true
}
},
Expand Down Expand Up @@ -93,7 +93,7 @@
"cross-env": "^7.0.3",
"eslint": "^7.25.0",
"esno": "^0.5.0",
"playwright": "^1.10.0",
"playwright-chromium": "^1.10.0",
"pnpm": "^6.2.2",
"rimraf": "^3.0.2",
"tsup": "^4.10.1",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ run('mkdir docs/public/demo')

run('npm run build')

run('npx slidev build slides.md --base /demo/composable-vue/', path.resolve(__dirname, '../demo'))
run('npx slidev build slides.md -d --base /demo/composable-vue/', path.resolve(__dirname, '../demo'))
run('cp -R demo/dist docs/public/demo/composable-vue')

run('cp packages/create-app/template/slides.md demo/build.md')
run('cp -R packages/create-app/template/public demo')
run('npx slidev build build.md --base /demo/starter/', path.resolve(__dirname, '../demo'))
run('npx slidev build build.md -d --base /demo/starter/', path.resolve(__dirname, '../demo'))

run('cp -R demo/dist docs/public/demo/starter')

Expand Down
29 changes: 0 additions & 29 deletions scripts/netlify.ts

This file was deleted.

0 comments on commit 73fcba2

Please sign in to comment.