feat: support page with trailing '.html'#111
Conversation
|
This is necessary even with the following config, server:
serveStatic:
extensions:
- htmlbecause currently hexo-server always add a trailing slash; Current behavior: source is source/bar.md Expected behavior: |
| res.end('Redirecting'); | ||
| return; | ||
| if (route.get(url + '/index.html')) { | ||
| // When the URL is `foo/index.html` but users access `foo`, redirect to `foo/`. |
There was a problem hiding this comment.
What if foo/index.html & foo.html both existed?
Should we prefer foo.html before redirect to foo/index.html?
There was a problem hiding this comment.
If request is foo, foo/index.html takes priority.
I assume source/foo/index.md is more common (if hexo-server is used in production) as hexo-server currently doesn't support foo => source/foo.md.
If the priority is switched, it could be a breaking change.
just to clarify, foo/ is always proxied to foo/index.html.
There was a problem hiding this comment.
I have set up a simple example on Netlify: https://pretty-url.netlify.com/
Here are 4 links:
- https://pretty-url.netlify.com/foo.html =>
/foo.html - https://pretty-url.netlify.com/foo =>
/foo.html - https://pretty-url.netlify.com/foo/index.html =>
/foo/index.html - https://pretty-url.netlify.com/foo/ =>
301 /foo
There was a problem hiding this comment.
Here is another example on GitHub Pages: https://github.com/SukkaLab/pretty-url/
- https://lab.skk.moe/pretty-url/foo.html =>
/foo.html - https://lab.skk.moe/pretty-url/foo =>
/foo.html - https://lab.skk.moe/pretty-url/foo/index.html =>
/foo/index.html - https://lab.skk.moe/pretty-url/foo/ =>
/foo/index.html
There was a problem hiding this comment.
https://pretty-url.netlify.com/foo.html => /foo.html
https://pretty-url.netlify.com/foo => /foo.html
https://pretty-url.netlify.com/foo/index.html => /foo/index.html
https://pretty-url.netlify.com/foo/ => 301 /foo
/foo/ redirects to /foo which is then proxied to /foo.html?
Anyhow, I consider foo/index.html + foo.html to be invalid, not an edge case. Besides, hexo new page creates source/foo/index.md by default. So, if foo.html is prioritized, route.get() is more likely to be called three times, versus two in foo/index.html.
There was a problem hiding this comment.
/foo/redirects to/foowhich is then proxied to/foo.html?
So I prefer the GitHub Pages' behavior:
/foo/ => /foo/index.html
/foo => /foo.html
For hexo-server, when /foo is requested, we should find foo.html first, then find /foo/index.html
There was a problem hiding this comment.
if (route.get(url + '.html')) {
// serve the page
} else if (route.get(url + '/index.html')) {
// redirect to "url/"...
}There was a problem hiding this comment.
For hexo-server, when
/foois requested, we should findfoo.htmlfirst, then find/foo/index.html
Even if it's the default behavior of gh-pages/apache/nginx, shouldn't we follow hexo's default behavior?
hexo new pagecreatessource/foo/index.mdby default.
I meant to convey that source/foo/index.md should be more common, even though source/foo.md is supported as well.
There was a problem hiding this comment.
@curbengh No matter how common source/foo/index.md is, the point is if source/foo/index.md and source/foo.md both exists, then source/foo.md will no longer be accessible through /foo, which is not consistent with hexo's current pretty_url as well (Since the pretty_url is designed to be consistent with the platform the Hexo will be deployed to).
There was a problem hiding this comment.
I've changed the order:
Location foo/bar.html & foo/bar/index.html
Request foo/bar
Respond foo/bar.html via transparent proxy
Location foo/bar.html & foo/bar/index.html
Request foo/bar/
Respond foo/bar/index.html via transparent proxy
9106515 to
83473c9
Compare
|
After hexojs/hexo#4359, hexo-server also needs to support |
|
Shall we prioritize File: File: File: File: File: File:
|
TL;DR compatibility with
pretty_urls.trailing_html = falseCurrently hexo-server supports redirects like,
But not when source is located at
source/bar.md, which requires url to befoo.com/bar.html. This can be an issue whenpretty_urls.trailing_htmlis disabled.With this PR,
Existing redirect/proxy still works.
Also tested with custom
root: /root/andserver.compress.Edit:
File:
/foo/bar/index.htmlRequest:
/foo/bar/Respond: No redirect, serves file directly
File:
/foo/bar/index.htmlRequest:
/foo/barRespond: Redirect to
/foo/bar/and serve using example 1.File:
/foo/bar/index.htmlRequest:
/foo/bar/index.htmlRespond: If
pretty_urls.pretty_urls.trailing_index === false, redirect to/foo/bar/and serve using example 1; otherwise, no redirect and serves/foo/bar/index.html.File:
/foo/bar.htmlRequest:
/foo/barRespond: No redirect, serves file directly
File:
/foo/bar.htmlRequest:
/foo/bar/Respond: Redirect to
/foo/barand serve using example 4.File:
/foo/bar.htmlRequest:
/foo/bar.htmlRespond: If
pretty_urls.pretty_urls.trailing_html === false, redirect to/foo/barand serve using example 4; otherwise, no redirect and serves/foo/bar.html.