Files
2026-08-29 18:59:33 +08:00

44 lines
1.4 KiB
TypeScript

import 'dotenv/config'
import { mkdir } from 'node:fs/promises'
import path from 'node:path'
import { loadProjectConfig } from './lib/config.ts'
import { resolveDeck } from './lib/content.ts'
import { runSlidev } from './lib/run-slidev.ts'
import { resolveTheme } from './lib/theme.ts'
const args = process.argv.slice(2)
const slug = args.find(argument => !argument.startsWith('-'))
const formatIndex = args.indexOf('--format')
const format = formatIndex >= 0 ? args[formatIndex + 1] : 'pdf'
const allowed = new Set(['pdf', 'png', 'pptx', 'md'])
if (!allowed.has(format))
throw new Error(`不支持导出格式:${format}`)
const config = await loadProjectConfig()
const deck = await resolveDeck(slug, process.cwd(), config.slidesDir)
const exportDir = path.join(process.cwd(), config.exportDir)
await mkdir(exportDir, { recursive: true })
const output = path.join(exportDir, `${deck.slug}.${format}`)
const slidevArgs = [
'export',
deck.entry,
'--theme',
resolveTheme(config.theme),
'--format',
format,
'--output',
output,
]
// Slidev's one-piece exporter may capture off-screen lazy images before they
// are painted. Per-slide export renders each canvas as the active slide and is
// reliable for Markdown images across PNG, PDF, and screenshot-based PPTX.
if (format !== 'md')
slidevArgs.push('--per-slide')
await runSlidev(slidevArgs)
console.log(`导出完成:${path.relative(process.cwd(), output)}`)