Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3fafaa

Browse files
authored
fix: theme ejection (#2085)
1 parent 7fa7d78 commit f3fafaa

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/slidev/node/cli.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveOptions } from './options'
2020
import { parser } from './parser'
2121
import { getRoots, isInstalledGlobally, resolveEntry } from './resolver'
2222
import setupPreparser from './setups/preparser'
23+
import { updateFrontmatterPatch } from './utils'
2324

2425
const CONFIG_RESTART_FIELDS: (keyof SlidevConfig)[] = [
2526
'monaco',
@@ -420,17 +421,19 @@ cli.command(
420421
}
421422
const [name, root] = (await resolveTheme(themeRaw, entry)) as [string, string]
422423

424+
await fs.mkdir(path.resolve(dir), { recursive: true })
423425
await fs.cp(
424426
root,
425427
path.resolve(dir),
426428
{
427-
filter: i => !/node_modules|.git/.test(path.relative(root, i)),
429+
recursive: true,
430+
filter: i => !/node_modules|\.git/.test(path.relative(root, i)),
428431
},
429432
)
430433

431434
const dirPath = `./${dir}`
432435
const firstSlide = data.entry.slides[0]
433-
firstSlide.frontmatter.theme = dirPath
436+
updateFrontmatterPatch(firstSlide, { theme: dirPath })
434437
parser.prettifySlide(firstSlide)
435438
await parser.save(data.entry)
436439

packages/slidev/node/utils.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ResolvedFontOptions, SlideInfo } from '@slidev/types'
1+
import type { ResolvedFontOptions, SourceSlideInfo } from '@slidev/types'
22
import type MarkdownIt from 'markdown-it'
33
import type { Connect } from 'vite'
44
import { fileURLToPath } from 'node:url'
@@ -48,15 +48,14 @@ export function generateCoollabsFontsUrl(options: ResolvedFontOptions) {
4848
/**
4949
* Update frontmatter patch and preserve the comments
5050
*/
51-
export function updateFrontmatterPatch(slide: SlideInfo, frontmatter: Record<string, any>) {
52-
const source = slide.source
51+
export function updateFrontmatterPatch(source: SourceSlideInfo, frontmatter: Record<string, any>) {
5352
let doc = source.frontmatterDoc
5453
if (!doc) {
5554
source.frontmatterStyle = 'frontmatter'
5655
source.frontmatterDoc = doc = new YAML.Document({})
5756
}
5857
for (const [key, value] of Object.entries(frontmatter)) {
59-
slide.frontmatter[key] = source.frontmatter[key] = value
58+
source.frontmatter[key] = value
6059
if (value == null) {
6160
doc.delete(key)
6261
}

packages/slidev/node/vite/loaders.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ export function createSlidesLoader(
107107
}
108108
if (body.note)
109109
slide.note = slide.source.note = body.note
110-
if (body.frontmatter)
111-
updateFrontmatterPatch(slide, body.frontmatter)
110+
if (body.frontmatter) {
111+
updateFrontmatterPatch(slide.source, body.frontmatter)
112+
Object.assign(slide.frontmatter, body.frontmatter)
113+
}
112114

113115
parser.prettifySlide(slide.source)
114116
const fileContent = await parser.save(data.markdownFiles[slide.source.filepath])

0 commit comments

Comments
 (0)