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

clean-url plugin breaks Netlify deployment #1385

Closed
1 task done
vladfaust opened this issue Mar 2, 2019 · 7 comments
Closed
1 task done

clean-url plugin breaks Netlify deployment #1385

vladfaust opened this issue Mar 2, 2019 · 7 comments
Labels
has workaround Has a workaround topic: plugins Relates to VuePress plugins

Comments

@vladfaust
Copy link

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

Bug report

Version

alpha.40

Steps to reproduce

Visit https://compassionate-benz-c091d6.netlify.com/getting-started

What is expected?

A rendered page equal to https://docs.onyxframework.org/getting-started

What is actually happening?

Both websites are deployed via Netlify. https://docs.onyxframework.org is deployed from master branch, https://compassionate-benz-c091d6.netlify.com — from bug branch. The only difference is that the clean-urls plugin enabled in bug branch as seen here: https://github.com/onyxframework/docs/compare/bug.

See https://github.com/onyxframework/docs for the source code.

Other relevant information

@shigma shigma added the topic: plugins Relates to VuePress plugins label Mar 2, 2019
@shigma
Copy link
Collaborator

shigma commented Mar 2, 2019

I admit that I did not clarify this in the document and I will add some caveats to it.

VuePress does not have the right to modify server identification. If you want your URLs to follow a certain pattern (e.g. /rest/routing instead of rest/routing.html or rest/routing/), you should make sure that your server would treat it as an HTML. So this question is not in the scope of VuePress.

However, I still don't know why plugin-clean-urls works in your master branch. @jjyyxx

Here is a related issue: #1382.

@vladfaust
Copy link
Author

vladfaust commented Mar 2, 2019

@shigma I see. Handling pages as HTML is a server's responsibility.

However, I still don't know why plugin-clean-urls works in your master branch

The thing is that I actually do not have this plugin enabled in the master branch. I double-checked that Netlify has asset optimization disabled (and even forcibly re-deployed the site). Still, https://docs.onyxframework.org/getting-started is working (but immediately gets redirected to https://docs.onyxframework.org/getting-started.html). So, looks like it's some Netlify stuff.

Nevertheless, is it somehow possible to make https://docs.onyxframework.org/getting-started links work without redirecting to .html (so the link stays pretty in the address bar) on Netlify? I'd be happy if someone could help me with that...

@shigma
Copy link
Collaborator

shigma commented Mar 2, 2019

@vladfaust

Most of the servers will automatically handle some redirects, e.g. when /foo does not exist:

  • /foo -> /foo.html if exists
  • /foo -> /foo/ if exists

(And to behonest, #1269 does not work on any server.) So if you want a /foo without redirection on Netlify without additional configuration, make sure:

  • /foo exists, and
  • /foo.html and /foo/ does not exist

@vladfaust
Copy link
Author

@shigma in my case on master branch the dist folder looks like this:

.
├── getting-started.html

Both https://docs.onyxframework.org/getting-started.html and https://docs.onyxframework.org/getting-started work.

And the bug branch (with clean-urls enabled) dist folder looks like this:

.
├── getting-started

Neither https://compassionate-benz-c091d6.netlify.com/getting-started nor https://compassionate-benz-c091d6.netlify.com/getting-started.html work.

This falls under your advice:

make sure:

  • /foo exists, and
  • /foo.html and /foo/ does not exist

But does not work. Netlify doesn't want to treat getting-started as an HTML page.

@alberthaff
Copy link

alberthaff commented Mar 3, 2019

I made a little hotfix-script.

Place following in your package.json

"scipts": {
  "build": "vuepress build; npm run urls:pretty",
  "urls:pretty": "find ./.vuepress/dist ! -path './img*' ! -path './assets*' ! -name '_redirects' ! -name '*.*' -type f -exec bash -c 'mv $1 $1.temp; mkdir $1; mv $1.temp $1/index.html' - {} \\;"
}

and run npm run build as usual. The script renames all page from getting-started to getting-started/index.html. It works fine on ngx-buoy.com (hosted with Netlify),

You'll might have to adjust the filter of the script, so that it doesn't rename your assets, etc.

You have to disable Netlify's "pretty URLs" to get rid of the trailing slashes

@shigma shigma added the has workaround Has a workaround label Mar 4, 2019
@shigma shigma closed this as completed Mar 4, 2019
@brianmercer
Copy link

Another workaround for using the clean-url plugin with netlify. Set the content-type header in netlify.toml or a _headers for your specific paths, i.e. netlify.toml:

[[headers]]
  for = "/posts/*"
  [headers.values]
    Content-Type = "text/html; charset=utf-8"
[[headers]]
  for = "/about"
  [headers.values]
    Content-Type = "text/html; charset=utf-8"

However, I do still think this is a bug. You should be able to set the path as /posts/my-page and have vuepress write out /posts/my-page.html. That is the typical solution for non-spa static files and hosts have server rules to handle that. I don't see how a plugin can solve that since when vuepress renders the page the filename is based on the path, even if regularPath still has the html extension.

{ "title": "Test Page", "frontmatter": { "title": "Test Page" }, "regularPath": "/posts/test.html", "relativePath": "posts/test.md", "key": "v-27be7c86", "path": "/posts/test" }

@slanden
Copy link

slanden commented Aug 21, 2019

The problem with setting Netlify headers is that your own CSS for the page doesn't get rendered, only the browser defaults. At least, this was my experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround Has a workaround topic: plugins Relates to VuePress plugins
Projects
None yet
Development

No branches or pull requests

5 participants