Skip to content

Commit f90e56d

Browse files
committed
feat: support local theme
1 parent d5aad3c commit f90e56d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/slidev/node/options.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,25 @@ export function getCLIRoot() {
6161
return resolve(__dirname, '..')
6262
}
6363

64-
export function getThemeRoots(name: string) {
64+
export function isRelative(name: string) {
65+
return /^\.\.?[\/\\]/.test(name)
66+
}
67+
68+
export function getThemeRoots(name: string, entry: string) {
6569
if (!name)
6670
return []
6771

68-
return [
69-
dirname(require.resolve(`${name}/package.json`)),
70-
]
72+
// TODO: handle theme inherit
73+
if (isRelative(name)) {
74+
return [
75+
resolve(dirname(entry), name),
76+
]
77+
}
78+
else {
79+
return [
80+
dirname(require.resolve(`${name}/package.json`)),
81+
]
82+
}
7183
}
7284

7385
export async function resolveOptions(
@@ -95,7 +107,7 @@ export async function resolveOptions(
95107

96108
const clientRoot = getClientRoot()
97109
const cliRoot = getCLIRoot()
98-
const themeRoots = getThemeRoots(theme)
110+
const themeRoots = getThemeRoots(theme, entry)
99111
const roots = uniq([clientRoot, ...themeRoots, userRoot])
100112

101113
return {

packages/slidev/node/themes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import prompts from 'prompts'
22
import { parseNi, run } from '@antfu/ni'
3+
import { isRelative } from './options'
34

45
const officialThemes: Record<string, string> = {
56
none: '',
@@ -21,6 +22,8 @@ export function resolveThemeName(name: string) {
2122
return ''
2223
if (name.startsWith('@slidev/theme-') || name.startsWith('slidev-theme-'))
2324
return name
25+
if (name.startsWith('.'))
26+
return name
2427
if (officialThemes[name] !== null)
2528
return officialThemes[name]
2629

@@ -32,7 +35,7 @@ export async function promptForThemeInstallation(name: string) {
3235
if (!name)
3336
return name
3437

35-
if (packageExists(name))
38+
if (isRelative(name) || packageExists(name))
3639
return name
3740

3841
const { confirm } = await prompts({

0 commit comments

Comments
 (0)