Skip to content

Commit 06901fc

Browse files
committed
feat: support custom download url for build
1 parent 204105f commit 06901fc

File tree

7 files changed

+28
-13
lines changed

7 files changed

+28
-13
lines changed

demo/slides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: cover
3+
download: https://antfu.me/talks/2021-04-29
34
---
45

56
# Composable Vue

docs/guide/exporting.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Exporting
22

3+
> Exporting is relying on [Playwright](https://playwright.dev) to do the rendering, you will need to install [`playwright-chromium`](https://playwright.dev/docs/installation#download-single-browser-binary) for using this feature.
4+
> If you are doing exporting in a CI environment, [this guide](https://playwright.dev/docs/ci) could also be helpful.
5+
36
## PDF
47

58
Exporting your slides into PDF by the following command
@@ -35,11 +38,16 @@ You can provide a downloadable PDF to the viewers of your SPA. You can enable it
3538

3639
```md
3740
---
38-
allow-download: true
41+
download: true
3942
---
4043
```
4144

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

44-
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)
47+
You can also provide a custom url to the PDF. And if so the rendering process will be skipped.
4548

49+
```md
50+
---
51+
download: 'https://myside.com/my-talk.pdf'
52+
---
53+
```

packages/client/internals/NavControls.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { useFullscreen } from '@vueuse/core'
33
import { computed, defineProps } from 'vue'
4+
import { isString } from '@antfu/utils'
45
import { isDark, toggleDark } from '../logic/dark'
56
import { hasNext, hasPrev, prev, next, isPresenter, currentPage } from '../logic/nav'
67
import { showOverview, showEditor } from '../state'
@@ -18,9 +19,14 @@ const { isFullscreen, toggle: toggleFullscreen } = useFullscreen(document.body)
1819
const presenterLink = computed(() => `${location.origin}/presenter/${currentPage.value}`)
1920
const nonPresenterLink = computed(() => `${location.origin}/${currentPage.value}`)
2021
21-
function downloadPDF() {
22-
import('file-saver')
23-
.then(i => i.saveAs(`${import.meta.env.BASE_URL}slidev-exported.pdf`, `${configs.title}.pdf`))
22+
async function downloadPDF() {
23+
const { saveAs } = await import('file-saver')
24+
saveAs(
25+
isString(configs.download)
26+
? configs.download
27+
: `${import.meta.env.BASE_URL}slidev-exported.pdf`,
28+
`${configs.title}.pdf`,
29+
)
2430
}
2531
</script>
2632

@@ -68,7 +74,7 @@ function downloadPDF() {
6874
</button>
6975
</template>
7076
<template v-else>
71-
<button v-if="configs.allowDownload" class="icon-btn" @click="downloadPDF">
77+
<button v-if="configs.download" class="icon-btn" @click="downloadPDF">
7278
<carbon:download />
7379
</button>
7480
</template>

packages/slidev/node/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function build(
4040
await fs.unlink(indexPath)
4141
}
4242

43-
if (options.data.config.allowDownload) {
43+
if (options.data.config.download === true || options.data.config.download === 'auto') {
4444
const port = 12445
4545
const app = connect()
4646
const server = http.createServer(app)

packages/slidev/node/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ cli.command(
107107
type: 'string',
108108
describe: 'output base',
109109
})
110-
.option('allowDownload', {
110+
.option('download', {
111111
alias: 'd',
112112
type: 'boolean',
113113
describe: 'allow download as PDF',
114114
})
115115
.help(),
116-
async({ entry, theme, watch, base, allowDownload }) => {
116+
async({ entry, theme, watch, base, download }) => {
117117
const { build } = await import('./build')
118118

119119
const options = await resolveOptions({ entry, theme }, 'build')
120-
if (allowDownload)
121-
options.data.config.allowDownload = allowDownload
120+
if (download && !options.data.config.download)
121+
options.data.config.download = download
122122

123123
printInfo(options)
124124
await build(options, {}, {

packages/slidev/node/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function parse(
120120
config.title ??= headmatter.title ?? (slides[0].content.match(/^# (.*)$/m)?.[1] || '').trim()
121121
config.remoteAssets ??= headmatter.remoteAssets ?? true
122122
config.monaco ??= headmatter.monaco ?? 'dev'
123-
config.allowDownload ??= (<any>config)['allow-download'] ?? headmatter.allowDownload ?? headmatter['allow-download'] ?? true
123+
config.download ??= headmatter.download ?? false
124124

125125
return {
126126
raw: markdown,

packages/types/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface SlidevConfig {
2828
/**
2929
* @default true
3030
*/
31-
allowDownload: boolean
31+
download: boolean | string
3232
}
3333

3434
export interface SlidevMarkdown {

0 commit comments

Comments
 (0)