Skip to content

Commit 6407d71

Browse files
committed
feat: some enhancements
1 parent fe266e2 commit 6407d71

File tree

18 files changed

+400
-255
lines changed

18 files changed

+400
-255
lines changed

CHANGELOG.md

100644100755
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,20 @@
2323

2424
* **$core:** support global layout (close: [#1226](https://github.com/vuejs/vuepress/issues/1226)) ([c91f55a](https://github.com/vuejs/vuepress/commit/c91f55a))
2525

26-
From now on, users have the ability to use a custom global layout component via [siteConfig](https://vuepress.vuejs.org/miscellaneous/glossary.html#siteconfig) or [themeEntryFile](https://vuepress.vuejs.org/miscellaneous/glossary.html#themeentryfile):
26+
From now on, users have the ability to use a custom global layout component via [siteConfig](https://vuepress.vuejs.org/miscellaneous/glossary.html#siteconfig) or [themeEntry](https://vuepress.vuejs.org/miscellaneous/glossary.html#themeentry):
2727

2828
```js
2929
module.exports = {
3030
globalLayout: '/path/to/your/global/vue/sfc'
3131
}
3232
```
3333

34-
Here is the [content of default global layout component](https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/core/lib/app/components/GlobalLayout.vue), an example of setting global header and footer:
35-
36-
```vue
37-
<template>
38-
<div id="global-layout">
39-
<header><h1>Header</h1></header>
40-
<component :is="layout"/>
41-
<footer><h1>Footer</h1></footer>
42-
</div>
43-
</template>
44-
45-
<script>
46-
export default {
47-
computed: {
48-
layout () {
49-
if (this.$page.path) {
50-
if (this.$vuepress.isLayoutExists(this.$page.frontmatter.layout)) {
51-
return this.$page.frontmatter.layout
52-
}
53-
return 'Layout'
54-
}
55-
return 'NotFound'
56-
}
57-
}
58-
}
59-
</script>
60-
```
61-
34+
Here is the [content of default global layout component](https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/core/lib/app/components/GlobalLayout.vue),
6235
Also, you can follow the convention, directly create a component `.vuepress/components/GlobalLayout.vue` or `themePath/layouts/GlobalLayout.vue` without any config. the loading priority is as follows:
6336

6437
- siteConfig
6538
- siteAgreement
66-
- themeEntryFile
39+
- themeEntry
6740
- themeAgreement
6841
- default
6942

packages/@vuepress/core/lib/internal-plugins/enhanceApp.js

100644100755
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ module.exports = (options, context) => ({
66
enhanceAppFiles () {
77
const { sourceDir, themeAPI } = context
88
const enhanceAppPath = path.resolve(sourceDir, '.vuepress/enhanceApp.js')
9-
const themeEnhanceAppPath = path.resolve(themeAPI.theme.path, 'enhanceApp.js')
10-
const files = [
11-
enhanceAppPath,
12-
themeEnhanceAppPath
13-
]
9+
const files = [enhanceAppPath]
1410
if (themeAPI.existsParentTheme) {
1511
files.push(path.resolve(themeAPI.parentTheme.path, 'enhanceApp.js'))
1612
}
13+
const themeEnhanceAppPath = path.resolve(themeAPI.theme.path, 'enhanceApp.js')
14+
files.push(themeEnhanceAppPath)
1715
return files
1816
}
1917
})

packages/@vuepress/core/lib/plugin-api/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ module.exports = class PluginAPI {
8484
if (isPlainObject(pluginRaw) && pluginRaw.$$normalized) {
8585
plugin = pluginRaw
8686
} else {
87-
plugin = this.normalizePlugin(pluginRaw, pluginOptions)
87+
try {
88+
plugin = this.normalizePlugin(pluginRaw, pluginOptions)
89+
} catch (e) {
90+
logger.warn(e.message)
91+
}
8892
}
8993

9094
if (plugin.multiple !== true) {
@@ -114,8 +118,7 @@ module.exports = class PluginAPI {
114118
normalizePlugin (pluginRaw, pluginOptions = {}) {
115119
let plugin = this._pluginResolver.resolve(pluginRaw)
116120
if (!plugin.entry) {
117-
console.warn(`[vuepress] cannot resolve plugin "${pluginRaw}"`)
118-
return this
121+
throw new Error(`[vuepress] cannot resolve plugin "${pluginRaw}"`)
119122
}
120123
plugin = flattenPlugin(plugin, pluginOptions, this._pluginContext, this)
121124
plugin.$$normalized = true

packages/@vuepress/core/lib/prepare/AppContext.js

100644100755
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ module.exports = class AppContext {
252252
*/
253253

254254
resolveGlobalLayout () {
255-
const GLOBAL_LAYOUT_COMPONENT_NAME = `GlobalLayout`
256-
257255
this.globalLayout = this.resolveCommonAgreementFilePath(
258256
'globalLayout',
259257
{
260-
defaultValue: path.resolve(__dirname, `../app/components/${GLOBAL_LAYOUT_COMPONENT_NAME}.vue`),
261-
siteAgreement: `components/${GLOBAL_LAYOUT_COMPONENT_NAME}.vue`,
262-
themeAgreement: `layouts/${GLOBAL_LAYOUT_COMPONENT_NAME}.vue`
258+
defaultValue: path.resolve(__dirname, `../app/components/GlobalLayout.vue`),
259+
siteAgreement: `components/GlobalLayout.vue`,
260+
themeAgreement: `layouts/GlobalLayout.vue`
263261
}
264262
)
265263

packages/@vuepress/core/lib/prepare/loadTheme.js

100644100755
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = function loadTheme (ctx) {
3737
if (!theme.path) {
3838
throw new Error(`[vuepress] You must specify a theme, or create a local custom theme. \n For more details, refer to https://vuepress.vuejs.org/guide/custom-themes.html#custom-themes. \n`)
3939
}
40+
logger.tip(`Apply theme ${chalk.gray(theme.name)}`)
4041
theme.entry.name = '@vuepress/internal-theme-entry-file'
4142

4243
let parentTheme = {}
@@ -45,14 +46,22 @@ module.exports = function loadTheme (ctx) {
4546
parentTheme.entry.name = '@vuepress/internal-parent-theme-entry-file'
4647
}
4748

49+
logger.debug('theme', theme.name, theme.path)
50+
logger.debug('parentTheme', parentTheme.name, parentTheme.path)
4851
return new ThemeAPI(theme, parentTheme, ctx)
4952
}
5053

5154
function normalizeThemePath (resolved) {
5255
const { entry, name, fromDep } = resolved
5356
if (fromDep) {
5457
const pkgPath = require.resolve(name)
55-
return parse(pkgPath).dir
58+
let packageRootDir = parse(pkgPath).dir
59+
// For those cases that "main" field was set to non-index file
60+
// e.g. `layouts/Layout.vue`
61+
while (!fs.existsSync(`${packageRootDir}/package.json`)) {
62+
packageRootDir = resolve(packageRootDir, '..')
63+
}
64+
return packageRootDir
5665
} else if (entry.endsWith('.js') || entry.endsWith('.vue')) {
5766
return parse(entry).dir
5867
} else {
@@ -89,7 +98,6 @@ function resolveTheme (ctx, resolver, ignoreLocal, theme) {
8998
path = normalizeThemePath(resolved)
9099
name = resolved.name
91100
shortcut = resolved.shortcut
92-
logger.tip(`Apply theme ${chalk.gray(name)}`)
93101
} else {
94102
return {}
95103
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<header>Header</header>
4+
<Content/>
5+
<footer>Footer</footer>
6+
</div>
7+
</template>
8+
9+
<style>
10+
11+
</style>

packages/@vuepress/theme-vue/components/Home.vue

Lines changed: 0 additions & 162 deletions
This file was deleted.

packages/docs/docs/.vuepress/config.js

100644100755
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ module.exports = ctx => ({
7676
ga: 'UA-128189152-1'
7777
}],
7878
],
79-
clientRootMixin: path.resolve(__dirname, 'mixin.js'),
79+
clientRootMixin: ctx.isProd
80+
? path.resolve(__dirname, 'mixin.js')
81+
: [],
8082
extendMarkdown (md) {
8183
md.use(container, 'upgrade', {
8284
render: (tokens, idx) => tokens[idx].nesting === 1
@@ -161,7 +163,8 @@ function getThemeSidebar (groupA, introductionA) {
161163
'using-a-theme',
162164
'writing-a-theme',
163165
'option-api',
164-
'default-theme-config'
166+
'default-theme-config',
167+
'inheritance'
165168
]
166169
},
167170
]

packages/docs/docs/miscellaneous/glossary.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Value of `themeConfig` in `.vuepress/config.js`, i.e., `user's theme configurati
5656
5757
Root path (absolute path) of the currently used theme.
5858

59-
## themeEntryFile
59+
## themeEntry
6060

6161
> Access: `Context.themeAPI.theme.entry`
6262
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Theme Inheritance
2+
3+
## Motivation
4+
5+
6+
7+
## What is Subject Inheritance?
8+
9+

packages/docs/docs/theme/option-api.md

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Note that in the child theme, VuePress will apply a `@parent-theme` [alias](../p
3232

3333
- [Example: `@vuepress/theme-vue`](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/theme-vue)
3434
- [Design Concepts of VuePress 1.x](../miscellaneous/design-concepts.md)
35+

0 commit comments

Comments
 (0)