Skip to content

Commit d27d77f

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

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
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/plugin-blog/index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,21 @@ module.exports = (options, ctx) => {
1616

1717
const enhancers = [
1818
{
19-
when: ({ regularPath }) => isDirectChild(regularPath),
20-
frontmatter: { layout: getLayout('Page', 'Layout') },
21-
data: { type: 'page' }
19+
when: ({ regularPath }) => regularPath === categoryIndexPageUrl,
20+
frontmatter: { layout: getLayout('Categories', 'Page') }
2221
},
2322
{
2423
when: ({ regularPath }) => regularPath.startsWith('/category/'),
2524
frontmatter: { layout: getLayout('Category', 'Page') }
2625
},
2726
{
28-
when: ({ regularPath }) => regularPath === categoryIndexPageUrl,
29-
frontmatter: { layout: getLayout('Categories', 'Page') }
27+
when: ({ regularPath }) => regularPath === tagIndexPageUrl,
28+
frontmatter: { layout: getLayout('Tags', 'Page') }
3029
},
3130
{
3231
when: ({ regularPath }) => regularPath.startsWith('/tag/'),
3332
frontmatter: { layout: getLayout('Tag', 'Page') }
3433
},
35-
{
36-
when: ({ regularPath }) => regularPath === tagIndexPageUrl,
37-
frontmatter: { layout: getLayout('Tags', 'Page') }
38-
},
3934
{
4035
when: ({ regularPath }) => regularPath === '/',
4136
frontmatter: { layout: getLayout('Layout') }
@@ -48,7 +43,12 @@ module.exports = (options, ctx) => {
4843
},
4944
data: { type: 'post' }
5045
},
51-
...pageEnhancers
46+
...pageEnhancers,
47+
{
48+
when: ({ regularPath }) => isDirectChild(regularPath),
49+
frontmatter: { layout: getLayout('Page', 'Layout') },
50+
data: { type: 'page' }
51+
}
5252
]
5353

5454
return {
@@ -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 (!rawFrontmatter[key]) {
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)