Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@plugin-blog): fix blog layout rendering error (close: #1073) #1095

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
Copy link
Member

@ulivz ulivz Dec 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would block the apply of other attrs (e.g. permalink ) in frontmatter ? actually I think the following override strategy should be right —— we should respect all the attrs which has been set in user's frontmatter.

if (!frontmatter[key]) {
  rawFrontmatter[key] = frontmatter[key]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I ignored this question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!frontmatter[key]) {
rawFrontmatter[key] || frontmatter[key]
}

Is this setting a bit problematic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= instead of ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I corrected this by the way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

})
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>