vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.43k stars 4.79k forks source link

relative links to additionalPages generate a spurious warning #1162

Open sullivanpt opened 5 years ago

sullivanpt commented 5 years ago

Bug report

Version

vuepress@1.0.0-alpha.30

Steps to reproduce

create a vuepress project with this plugin

module.exports = {
  additionalPages: [{
    permalink: '/section/ex-two.html',
    content: 'some content'
  }]
}

and this file /section/README.md with content

[A Link](/section/ex-two.md)

note: behavior is same if link is /section/ex-two.html

then run npm docs:dev

What is expected?

No warnings

Aside: the links work correctly. It's just the warning message that is undesired.

What is actually happening?

See this warning in console when building

File for relative link "/section/ex-two.md" does not exist.
(Resolved file: C:\Source\section\ex-two.md)

Other relevant information

mAKEkr commented 5 years ago

maybe this issue has on #881 same problem. this issue topic about "problem on additional page regist in build command". can you try applied #909 PR on your environment?

sullivanpt commented 5 years ago

@mAKEkr thanks for the suggestion, but from code inspection I don't see how it can help. The spurious warning comes from vuepress/packages/@vuepress/markdown-loader/index.js which assumes a physical file ending '.md' exists for the relative link. I think it needs to be changed to look at slugs too, but I'm not sure how to do that.

  // check if relative links are valid
  links && links.forEach(link => {
….
    if (!fs.existsSync(file) && (!altfile || !fs.existsSync(altfile))) {
      this.emitWarning(
        new Error(
          `\nFile for relative link "${link}" does not exist.\n` +
          `(Resolved file: ${file})\n`
        )
      )
    }
  })
ulivz commented 5 years ago

@mAKEkr They are two different things

mAKEkr commented 5 years ago

@ulivz @sullivanpt I'm sorry. I thought that the additionalpages were not registered in the build process. 😅 I tested on my environment, doesn't displaying any some of errors. can you provide reproduced repository?

sullivanpt commented 5 years ago

@mAKEkr sure https://github.com/sullivanpt/vuepress-issue-1162