Skip to content

Commit 896edcb

Browse files
committed
feat(cli): export in dark mode, close #80
1 parent ab5cd73 commit 896edcb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/slidev/node/cli.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ cli.command(
236236
type: 'string',
237237
describe: 'page ranges to export, for example "1,4-5,6"',
238238
})
239+
.option('dark', {
240+
default: false,
241+
type: 'boolean',
242+
describe: 'export as dark theme',
243+
})
239244
.strict()
240245
.help(),
241246
async({
@@ -245,6 +250,7 @@ cli.command(
245250
format,
246251
timeout,
247252
range,
253+
dark,
248254
}) => {
249255
output = output || `${path.basename(entry, '.md')}-export`
250256
process.env.NODE_ENV = 'production'
@@ -270,6 +276,7 @@ cli.command(
270276
format: format as any,
271277
output,
272278
timeout,
279+
dark,
273280
})
274281
console.log(`${green(' ✓ ')}${dim('exported to ')}./${output}\n`)
275282
server.close()

packages/slidev/node/export.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ExportOptions {
1414
format?: 'pdf' | 'png'
1515
output?: string
1616
timeout?: number
17+
dark?: boolean
1718
}
1819

1920
function createSlidevProgress() {
@@ -60,6 +61,7 @@ export async function exportSlides({
6061
output = 'slides',
6162
base = '/',
6263
timeout = 500,
64+
dark = false,
6365
}: ExportOptions) {
6466
if (!packageExists('playwright-chromium'))
6567
throw new Error('The exporting for Slidev is powered by Playwright, please installed it via `npm i playwright-chromium`')
@@ -78,6 +80,9 @@ export async function exportSlides({
7880

7981
async function go(no: number) {
8082
progress.update(no)
83+
84+
if (dark)
85+
await page.emulateMedia({ colorScheme: 'dark' })
8186
await page.goto(`http://localhost:${port}${base}${no}?print`, {
8287
waitUntil: 'networkidle',
8388
})

0 commit comments

Comments
 (0)