Skip to content

Commit bc170f9

Browse files
committed
fix(@plugin-blog): fix blog layout rendering error (close: vuejs#1073)
1 parent a56c3b4 commit bc170f9

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"dev": "yarn tsc && yarn workspace docs dev",
1414
"build": "yarn tsc && yarn workspace docs build",
1515
"show-help": "yarn workspace docs show-help",
16-
"dev:blog": "yarn workspace blog dev",
17-
"build:blog": "yarn workspace blog build",
16+
"dev:blog": "yarn tsc && yarn workspace blog dev",
17+
"build:blog": "yarn tsc && yarn workspace blog build",
1818
"register-vuepress": "lerna exec --scope vuepress -- yarn link",
1919
"lint": "eslint --fix packages/**/*.js packages/**/*.vue packages/**/bin/*",
2020
"release": "yarn --pure-lockfile && yarn tsc && node scripts/release.js",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const PLUGIN_OPTION_META_MAP = {
44
// hooks
5-
READY: { name: 'ready', types: [Function] },
5+
READY: { name: 'ready', types: [Function], async: true },
66
COMPILED: { name: 'compiled', types: [Function] },
77
UPDATED: { name: 'updated', types: [Function] },
88
GENERATED: { name: 'generated', types: [Function], async: true },

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module.exports = class AppContext {
111111
})
112112
)
113113

114-
await this.pluginAPI.options.ready.apply()
114+
await this.pluginAPI.options.ready.asyncApply()
115115
await Promise.all([
116116
this.pluginAPI.options.clientDynamicModules.apply(this),
117117
this.pluginAPI.options.enhanceAppFiles.apply(this),

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

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ module.exports = class Page {
128128
layout: this.key
129129
}, data)
130130
}
131+
132+
if (typeof this.frontmatter.layout === 'string') {
133+
this._hasInitLayout = true
134+
}
131135
}
132136

133137
// resolve i18n

packages/@vuepress/plugin-blog/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ module.exports = (options, ctx) => {
6565
}) => {
6666
if (when(pageCtx)) {
6767
Object.keys(frontmatter).forEach(key => {
68-
rawFrontmatter[key] = rawFrontmatter[key] || frontmatter[key]
68+
if (!pageCtx._hasInitLayout) {
69+
rawFrontmatter[key] = frontmatter[key]
70+
}
6971
})
7072
Object.assign(pageCtx, data)
7173
}
@@ -75,7 +77,7 @@ module.exports = (options, ctx) => {
7577
/**
7678
* Create tag page and category page.
7779
*/
78-
ready () {
80+
async ready () {
7981
const { pages } = ctx
8082
const tagMap = {}
8183
const categoryMap = {}
@@ -140,7 +142,7 @@ module.exports = (options, ctx) => {
140142
frontmatter: { title: `${categoryName} | Category` }
141143
}))
142144
]
143-
extraPages.forEach(page => ctx.addPage(page))
145+
await Promise.all(extraPages.map(page => ctx.addPage(page)))
144146
},
145147

146148
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div class="container">
3+
<h2>Now is Tags Page</h2>
4+
</div>
5+
</template>

0 commit comments

Comments
 (0)