-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: support page with trailing '.html' #111
Conversation
This is necessary even with the following config, server:
serveStatic:
extensions:
- html because currently hexo-server always add a trailing slash; Current behavior: source is source/bar.md
Expected behavior:
|
lib/middlewares/route.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/foo/
redirects to/foo
which 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For hexo-server, when
/foo
is requested, we should findfoo.html
first, 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 page
createssource/foo/index.md
by 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = false
Currently 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_html
is disabled.With this PR,
Existing redirect/proxy still works.
Also tested with custom
root: /root/
andserver.compress
.Edit:
File:
/foo/bar/index.html
Request:
/foo/bar/
Respond: No redirect, serves file directly
File:
/foo/bar/index.html
Request:
/foo/bar
Respond: Redirect to
/foo/bar/
and serve using example 1.File:
/foo/bar/index.html
Request:
/foo/bar/index.html
Respond: 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.html
Request:
/foo/bar
Respond: No redirect, serves file directly
File:
/foo/bar.html
Request:
/foo/bar/
Respond: Redirect to
/foo/bar
and serve using example 4.File:
/foo/bar.html
Request:
/foo/bar.html
Respond: If
pretty_urls.pretty_urls.trailing_html === false
, redirect to/foo/bar
and serve using example 4; otherwise, no redirect and serves/foo/bar.html
.