Skip to content

Commit

Permalink
fix(@plugin-blog): fix blog layout rendering error (close: #1073) (#1095
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Mrminfive authored and ulivz committed Dec 13, 2018
1 parent dc7be95 commit f8469eb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dev": "yarn tsc && yarn workspace docs dev",
"build": "yarn tsc && yarn workspace docs build",
"show-help": "yarn workspace docs show-help",
"dev:blog": "yarn workspace blog dev",
"build:blog": "yarn workspace blog build",
"dev:blog": "yarn tsc && yarn workspace blog dev",
"build:blog": "yarn tsc && yarn workspace blog build",
"register-vuepress": "lerna exec --scope vuepress -- yarn link",
"lint": "eslint packages --fix --ext .js,.vue",
"release": "yarn --pure-lockfile && yarn tsc && node scripts/release.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/plugin-api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const PLUGIN_OPTION_META_MAP = {
// hooks
READY: { name: 'ready', types: [Function] },
READY: { name: 'ready', types: [Function], async: true },
COMPILED: { name: 'compiled', types: [Function] },
UPDATED: { name: 'updated', types: [Function] },
GENERATED: { name: 'generated', types: [Function], async: true },
Expand Down
28 changes: 14 additions & 14 deletions packages/@vuepress/plugin-blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,21 @@ module.exports = (options, ctx) => {

const enhancers = [
{
when: ({ regularPath }) => isDirectChild(regularPath),
frontmatter: { layout: getLayout('Page', 'Layout') },
data: { type: 'page' }
when: ({ regularPath }) => regularPath === categoryIndexPageUrl,
frontmatter: { layout: getLayout('Categories', 'Page') }
},
{
when: ({ regularPath }) => regularPath.startsWith('/category/'),
frontmatter: { layout: getLayout('Category', 'Page') }
},
{
when: ({ regularPath }) => regularPath === categoryIndexPageUrl,
frontmatter: { layout: getLayout('Categories', 'Page') }
when: ({ regularPath }) => regularPath === tagIndexPageUrl,
frontmatter: { layout: getLayout('Tags', 'Page') }
},
{
when: ({ regularPath }) => regularPath.startsWith('/tag/'),
frontmatter: { layout: getLayout('Tag', 'Page') }
},
{
when: ({ regularPath }) => regularPath === tagIndexPageUrl,
frontmatter: { layout: getLayout('Tags', 'Page') }
},
{
when: ({ regularPath }) => regularPath === '/',
frontmatter: { layout: getLayout('Layout') }
Expand All @@ -48,7 +43,12 @@ module.exports = (options, ctx) => {
},
data: { type: 'post' }
},
...pageEnhancers
...pageEnhancers,
{
when: ({ regularPath }) => isDirectChild(regularPath),
frontmatter: { layout: getLayout('Page', 'Layout') },
data: { type: 'page' }
}
]

return {
Expand All @@ -65,8 +65,8 @@ module.exports = (options, ctx) => {
}) => {
if (when(pageCtx)) {
Object.keys(frontmatter).forEach(key => {
if (!frontmatter[key]) {
rawFrontmatter[key] || frontmatter[key]
if (!rawFrontmatter[key]) {
rawFrontmatter[key] = frontmatter[key]
}
})
Object.assign(pageCtx, data)
Expand All @@ -77,7 +77,7 @@ module.exports = (options, ctx) => {
/**
* Create tag page and category page.
*/
ready () {
async ready () {
const { pages } = ctx
const tagMap = {}
const categoryMap = {}
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = (options, ctx) => {
frontmatter: { title: `${categoryName} | Category` }
}))
]
extraPages.forEach(page => ctx.addPage(page))
await Promise.all(extraPages.map(page => ctx.addPage(page)))
},

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/@vuepress/theme-blog/layouts/Tags.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="container">
<h2>Now is Tags Page</h2>
</div>
</template>

0 comments on commit f8469eb

Please sign in to comment.