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

Blog-plugin: wrong rendering for the router '/tag/' and '/category/' #1073

Closed
1 task done
EliazTray opened this issue Dec 6, 2018 · 5 comments
Closed
1 task done
Labels
has PR Has a related PR

Comments

@EliazTray
Copy link

EliazTray commented Dec 6, 2018

  • I confirm that this is a issue rather than a question.

Bug report

Version

@vuepress 1.0.0-alpha.27

Steps to reproduce

  1. Create Layout.vue, Page.vue, Post.vue, Tag.vue, Tags.vue, Category.vue, Categories.vue under the 'layouts' directory.

  2. npm run dev

  3. visit /tag/.

image

What is expected?

It will use Cateogries.vue layout to render.

What is actually happening?

it used Page.vue layout to render.

Other relevant information

  • Your OS: macOs
  • Node.js version: v8.11.3
  • Browser version: Chrome 70.0.3538.110
  • Is this a global or local install? local
  • Which package manager did you use for the install?
    v1.0.0.alpha.27
@EliazTray EliazTray changed the title Blog-plugin: wrong rendering for the router /tag/ & /category/ Blog-plugin: wrong rendering for the router '/tag/' and '/category/' Dec 6, 2018
@tohutohu
Copy link

tohutohu commented Dec 6, 2018

I also encountered a similar problem.

The part of adding the page of the plugin is working properly.
However, that information is not properly passed to Layout.vue.

I added debug print.

build.js
https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/core/lib/build.js#L128-L132

  async function renderPage (page) {
    const pagePath = page.path
    readline.clearLine(process.stdout, 0)
    readline.cursorTo(process.stdout, 0)
    process.stdout.write(`Rendering page: ${pagePath}\n`)
    console.log('path: ', page.path) // add
    console.log('frontmatter: ', page.frontmatter) // add

LayoutDistoributor.vue
https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/core/lib/app/components/LayoutDistributor.vue

export default {
  computed: {
    layout () {
      console.log('path: ', this.$page.path) // add
      console.log('frontmatter: ', this.$page.frontmatter) // add
      if (this.$page.path) {
        return this.$page.frontmatter.layout || 'Layout'
      }
      return 'NotFound'
    }
  }
}

I got the following output.

Rendering page: /2018/12/04/index/
{ title: 'test article',
  date: 2018-12-04T00:00:00.000Z,
  layout: 'Post',
  permalink: '/:year/:month/:day/:slug' }
path:  /2018/12/04/index/
{ title: 'test article',
  date: '2018-12-04T00:00:00.000Z',
  layout: 'Post',
  permalink: '/:year/:month/:day/:slug' }
Rendering page: /tag/
{ title: 'Tags', layout: 'Tags' }
path:
{}
Rendering page: /category/
{ title: 'Categories', layout: 'Categories' }
path:
{}
Rendering page: /404.html
undefined
path:
{}

@EliazTray
Copy link
Author

@tohutohu
i found the problem in https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/plugin-blog/index.js#L67.

'/tag/' & '/category/' match the first condition of enhancers

when Page layout exists, it used the layout which exists....

@tohutohu
Copy link

tohutohu commented Dec 7, 2018

@EliazTray
Oh, I see. Thanks.

The problem between you and me may be different.

@Mrminfive
Copy link
Contributor

The new page of the blog plugin cannot be used because the getSiteData method has been executed before the plugin ready.

Mrminfive added a commit to Mrminfive/vuepress that referenced this issue Dec 12, 2018
@ulivz
Copy link
Member

ulivz commented Dec 12, 2018

Thanks to @Mrminfive , there has been a PR for this issue

@ulivz ulivz added the has PR Has a related PR label Dec 12, 2018
Mrminfive added a commit to Mrminfive/vuepress that referenced this issue Dec 13, 2018
@ulivz ulivz closed this as completed in f8469eb Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has PR Has a related PR
Projects
None yet
Development

No branches or pull requests

4 participants