Skip to content

Commit f82ea4d

Browse files
committed
better layout check
1 parent 9caada0 commit f82ea4d

File tree

1 file changed

+9
-8
lines changed
  • packages/@vuepress/core/lib/node/theme-api

1 file changed

+9
-8
lines changed

packages/@vuepress/core/lib/node/theme-api/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const { logger, fs, path: { resolve }} = require('@vuepress/shared-utils')
22
const readdirSync = dir => fs.existsSync(dir) && fs.readdirSync(dir) || []
33

44
module.exports = class ThemeAPI {
5-
constructor (theme, parentTheme) {
5+
constructor (theme, parentTheme, context) {
66
this.theme = theme
7+
this.context = context
78
this.parentTheme = parentTheme || {}
89
this.existsParentTheme = !!this.parentTheme.path
910
this.vuepressPlugin = {
@@ -69,22 +70,22 @@ module.exports = class ThemeAPI {
6970
// built-in named layout or not.
7071
const layoutComponentMap = resolveSFCs(layoutDirs)
7172

72-
const { Layout = {}, NotFound = {}} = layoutComponentMap
73+
const { Layout, NotFound } = layoutComponentMap
7374
// layout component does not exist.
74-
if (!Layout || !fs.existsSync(Layout.path)) {
75+
if (!Layout) {
7576
const fallbackLayoutPath = resolve(__dirname, 'Layout.fallback.vue')
7677
layoutComponentMap.Layout = {
7778
filename: 'Layout.vue',
7879
componentName: 'Layout',
7980
path: fallbackLayoutPath,
8081
isInternal: true
8182
}
82-
logger.warn(
83-
`[vuepress] Cannot resolve Layout.vue file in \n ${Layout.path},`
84-
+ `fallback to default layout: ${fallbackLayoutPath}`
85-
)
83+
if (this.context.globalLayout !== this.context.getLibFilePath('client/components/GlobalLayout.vue')) {
84+
// doesn't expect a Layout.vue when a custom GlobalLayout is registered
85+
logger.warn(`[vuepress] Cannot find Layout.vue, fallback to default layout.`)
86+
}
8687
}
87-
if (!NotFound || !fs.existsSync(NotFound.path)) {
88+
if (!NotFound) {
8889
layoutComponentMap.NotFound = {
8990
filename: 'NotFound.vue',
9091
componentName: 'NotFound',

0 commit comments

Comments
 (0)