From c18eb7cfde03290b312996358e89807d30aeff1e Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 26 Mar 2024 17:57:36 +0800 Subject: [PATCH 1/4] feat: add `--wait` option when exporting --- packages/slidev/node/cli.ts | 4 ++++ packages/slidev/node/commands/export.ts | 7 +++++++ packages/types/src/cli.ts | 1 + 3 files changed, 12 insertions(+) diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts index 716739153e..ef148dda99 100644 --- a/packages/slidev/node/cli.ts +++ b/packages/slidev/node/cli.ts @@ -571,6 +571,10 @@ function exportOptions(args: Argv) { type: 'number', describe: 'timeout for rendering the print page', }) + .option('wait', { + type: 'number', + describe: 'wait for the specified ms before exporting', + }) .option('range', { type: 'string', describe: 'page ranges to export, for example "1,4-5,6"', diff --git a/packages/slidev/node/commands/export.ts b/packages/slidev/node/commands/export.ts index 4308162045..95b72b6b18 100644 --- a/packages/slidev/node/commands/export.ts +++ b/packages/slidev/node/commands/export.ts @@ -22,6 +22,7 @@ export interface ExportOptions { format?: 'pdf' | 'png' | 'md' output?: string timeout?: number + wait?: number dark?: boolean routerMode?: 'hash' | 'history' width?: number @@ -156,6 +157,7 @@ export async function exportSlides({ slides, base = '/', timeout = 30000, + wait = 0, dark = false, routerMode = 'history', width = 1920, @@ -260,6 +262,9 @@ export async function exportSlides({ await element.evaluate(node => node.style.display = 'none') } } + // Wait for the given time + if (wait) + await page.waitForTimeout(wait) } async function getSlidesIndex() { @@ -503,6 +508,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption output, format, timeout, + wait, range, dark, withClicks, @@ -521,6 +527,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption range, format: (format || 'pdf') as 'pdf' | 'png' | 'md', timeout: timeout ?? 30000, + wait: wait ?? 0, dark: dark || options.data.config.colorSchema === 'dark', routerMode: options.data.config.routerMode, width: options.data.config.canvasWidth, diff --git a/packages/types/src/cli.ts b/packages/types/src/cli.ts index 86860ee263..c2de0ec31f 100644 --- a/packages/types/src/cli.ts +++ b/packages/types/src/cli.ts @@ -7,6 +7,7 @@ export interface ExportArgs extends CommonArgs { 'output'?: string 'format'?: string 'timeout'?: number + 'wait'?: number 'range'?: string 'dark'?: boolean 'with-clicks'?: boolean From b514887cefcbc7dcb5387df7344b247f35ef48db Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 26 Mar 2024 18:01:15 +0800 Subject: [PATCH 2/4] docs: add docs --- docs/guide/exporting.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/guide/exporting.md b/docs/guide/exporting.md index da323a9092..3a4216bd08 100644 --- a/docs/guide/exporting.md +++ b/docs/guide/exporting.md @@ -159,6 +159,15 @@ For big presentations you might want to increase the Playwright timeout with `-- $ slidev export --timeout 60000 ``` +### Wait + +Some parts of your slides may require a longer time to render. You can use the `--wait` option to +have an extra delay before exporting. + +```bash +$ slidev export --wait 10000 +``` + ### Executable path You can set the browser executable path for Playwright using `--executable-path` From cf48adff0d3238e014bf54f2c1177ab3eb533ad1 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 26 Mar 2024 18:03:36 +0800 Subject: [PATCH 3/4] fix: export notes --- packages/slidev/node/cli.ts | 7 +++++++ packages/slidev/node/commands/export.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts index ef148dda99..61966b85c1 100644 --- a/packages/slidev/node/cli.ts +++ b/packages/slidev/node/cli.ts @@ -501,12 +501,18 @@ cli.command( type: 'number', describe: 'timeout for rendering the print page', }) + .option('wait', { + default: 0, + type: 'number', + describe: 'wait for the specified ms before exporting', + }) .strict() .help(), async ({ entry, output, timeout, + wait, }) => { const { exportNotes } = await import('./commands/export') const port = await getPort(12445) @@ -528,6 +534,7 @@ cli.command( port, output: output || (options.data.config.exportFilename ? `${options.data.config.exportFilename}-notes` : `${path.basename(entryFile, '.md')}-export-notes`), timeout, + wait, }) console.log(`${green(' ✓ ')}${dim('exported to ')}./${result}\n`) diff --git a/packages/slidev/node/commands/export.ts b/packages/slidev/node/commands/export.ts index 95b72b6b18..d89ef3e6b1 100644 --- a/packages/slidev/node/commands/export.ts +++ b/packages/slidev/node/commands/export.ts @@ -70,6 +70,7 @@ export interface ExportNotesOptions { base?: string output?: string timeout?: number + wait?: number } function createSlidevProgress(indeterminate = false) { @@ -113,6 +114,7 @@ export async function exportNotes({ base = '/', output = 'notes', timeout = 30000, + wait = 0, }: ExportNotesOptions): Promise { const { chromium } = await importPlaywright() const browser = await chromium.launch() @@ -130,6 +132,9 @@ export async function exportNotes({ await page.waitForLoadState('networkidle') await page.emulateMedia({ media: 'screen' }) + if (wait) + await page.waitForTimeout(wait) + await page.pdf({ path: output, margin: { From 638c4a32ec9c0dfa5976cdb94557b1b8c668bb70 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 26 Mar 2024 18:08:26 +0800 Subject: [PATCH 4/4] chore: autofix --- docs/guide/exporting.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/guide/exporting.md b/docs/guide/exporting.md index 3a4216bd08..fe462c7322 100644 --- a/docs/guide/exporting.md +++ b/docs/guide/exporting.md @@ -161,8 +161,7 @@ $ slidev export --timeout 60000 ### Wait -Some parts of your slides may require a longer time to render. You can use the `--wait` option to -have an extra delay before exporting. +Some parts of your slides may require a longer time to render. You can use the `--wait` option to have an extra delay before exporting. ```bash $ slidev export --wait 10000