vuejs / vuepress

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

Including raw HTML files #1057

Open ChristopherPAndrews opened 5 years ago

ChristopherPAndrews commented 5 years ago

Bug report

HTML files placed in .vuepress/public are only sporadically available. Trying to navigate to them from a link elsewhere on the site results in a 404. However, reloading the page finds the content.

Version

0.14.4

Steps to reproduce

Create an .html file and place it in .vuepress/public. Create a link to it from another page on the site. try to follow the link.

What is expected?

I expect the page to load

What is actually happening?

We get a 404 error until the reload button is clicked.

Other relevant information

ulivz commented 5 years ago

Sorry but could you create a reproduction repo, I can basically confirm that what you said above is not an issue, or our website will not work.

BillyYccc commented 5 years ago

Hi! I met this problem too, this is a small reproducer https://github.com/BillyYccc/vuepress-reproducer, can you please take a look at it?

ChristopherPAndrews commented 5 years ago

Yes, Billy's example is what I was talking about.

BillyYccc commented 5 years ago

@ulivz ping

jpeyret commented 5 years ago

Same issue here. What I did notice was that you could cp index.html README.md (and leave it as is) and it works. ln -s index.html README.md does not work. You can also create a README.md and just paste in the relevant html, tags and all, and it will work too. But handling .html files directly didn't work for me.
macOS Sierra Vuepress 0.14.9 npm 6.8.0 webpack@4.29.5 global install, vuepress dev mode, node v10.15.0

bgschiller commented 5 years ago

@ulivz I believe this should no longer be marked "needs reproduction repo"

bgschiller commented 5 years ago

As a workaround, I've created the following component, to be dropped in .vuepress/components/StaticLink.vue:

<script>
export default {
  name: "StaticLink",
  render(h) {
    return h("a", { domProps: this.props }, this.$slots.default);
  }
};
</script>

Then, in a markdown file, you can use it like an a-tag, but it opts-out of vuepress' router behavior. In this example, I have a folder full of html at .vuepress/public/rdoc/

<StaticLink href="/rdoc/">Rdocs</StaticLink>
mhyrr commented 5 years ago

Getting the same problem here, also want to be able to reference static HTML docs from the navbar links defined in config.js. e.g.:

{ text: 'Links to HTML loaded in public folder', link: '/test.html'}

PeppeL-G commented 5 years ago

Me too. I have an external HTML file I need to host, but using the []() syntax in markdown to link to it doesn't work. My workaround is to write the link using the <a> element directly in the markdown file.

darioblanco commented 5 years ago

I have the same problem as @mhyrr, any other workaround than setting <a> elemenet in Markdown files?

rv-bsnyder commented 5 years ago

Has there been any movement on this?

ghost commented 4 years ago

I confirm that link in navbar to an html file is broken.

haoranpb commented 4 years ago

So basically, you can't use relative link to navigate to HTML files place under .vuepress/public folder, which I personally believe it's expected? Because the purpose of the public file is:

You may need to provide static assets that are not directly referenced in any of your Markdown or theme components - for example, favicons and PWA icons.

Everything you place under the public folder will be simply copied into the root directory. So the HTML files won't be registered as a page in the Vue-router, which causes the 404. And when you refresh the page or navigate to it by the absolute link, the page will be correctly fetched and displayed.

As for workarounds:

If you are looking for a fully customized page (without any layout pre-defined in the VuePress), which I believe you are since you try to use HTML files. You can:

If you want the HTML files to be treated like any other MarkDown files, you can simply rename it to *.md and move it out of the public folder, because MarkDown naturally supports HTML syntax, it should be working fine for now.

I think the real issue is not navigating to HTML files underpublic, is whether to support raw HTML files like:

└── docs
    ├── .vuepress/
    ├── guide
    │   ├── test.html
    │   └── README.md
    └── README.md
LbhFront-end commented 3 years ago

I have a problem that The report generated by the back end has more than 50000 lines of HTML. How can it be directly rendered with the corresponding navigation bar in combination with vuepress