-
Notifications
You must be signed in to change notification settings - Fork 11
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
Trailing slash gives 404 #64
Comments
These are web server redirect and not caused by Documenter:
Edit: This should have been posted to the Documenter issue (JuliaDocs/Documenter.jl#2473). |
It is caused by what files generated by Documenter are called and where they are stored. The root cause of this is that Documenter.jl's file structure names all files index.html and places them like I think the latter is a slightly better approach, but I don't know how to transition from the former to the latter without breaking almost all links. |
I'm quite confused here.
I always thought that these two URLs are equivalent, even without any "redirect" by the server, but in any case #64 (comment) indicates that that Github normalizes the URL to have the slash at the end. If that's the case, it makes sense for Documenter to take that into account and always produce links with a trailing slash
I think that's just because the "explanations" doesn't exist, right? I don't know what happened between 1.02. and 1.1.0, but this doesn't seem related to whether The page that does exist is https://chairmarks.lilithhafner.com/v1.1.0/tutorial.html As far as I can tell, this is what vanilla Documenter would have produced with the Does I very much think |
Unfortunately this is not something that Vitepress supports:
Not quite - without the trailing slash, it's up to the server. With the trailing slash, it auto resolves to so one can link to e.g. https://chairmarks.lilithhafner.com/v1.1.0/tutorial and that works fine, but https://chairmarks.lilithhafner.com/v1.1.0/tutorial/ will error because there is no folder and no index.html. I could manually generate a redirect page in Vitepress doesn't actually support the exact structure of Documenter, but Github Pages allows A lot of the work here was for the markdown backend in any case, so it should be fairly easy to switch to another backend or upstream to DocumenterMarkdown at some point after we have this working well and understand how to better support other static site generators. |
Oh, that's quite interesting! Thanks for that explanation! I still think you should change the behavior to always write only |
I don't know if this is a bug: In |
All of the |
In the interim, used this script to setup 200 redirects from https://chairmarks.lilithhafner.com/v1.1.0/tutorial/ to https://chairmarks.lilithhafner.com/v1.1.0/tutorial. function fix(root_url, root_path=".")
for (root, dirs, files) in walkdir(root_path)
for file in files
name, ext = splitext(file)
if ext === ".html" && name ∉ ("404", "index")
dir = joinpath(root, name)
if !isdir(dir)
mkdir(dir)
url = "https://"*normpath(joinpath(root_url, root, name))
open(joinpath(dir, "index.html"), "w") do io
write(io, """
<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to $url</title>
<meta http-equiv="refresh" content="0; URL=$url">
<link rel="canonical" href="$url">""")
end
end
end
end
end
end
fix("chairmarks.lilithhafner.com") |
No that does not give any additional flexibility. Assets stored in the source directory like this:
Build to this using Documenter:
Building to a directory structure that matches the source directory structure will not introduce name conflicts.
Vitepress could (should?) add symlinks from There's no substantive technical reason to prefer https://chairmarks.lilithhafner.com/v1.1.0/tutorial vs https://chairmarks.lilithhafner.com/v1.1.0/tutorial/ vs https://chairmarks.lilithhafner.com/v1.1.0/tutorial.html. I agree with Vitepress's style choice to use https://chairmarks.lilithhafner.com/v1.1.0/tutorial for the reasons I gave in JuliaDocs/Documenter.jl#2473 (comment). Github servers happen to redirect 404s at |
I meant that in general. I routinely use setups where generated assets get put in the same folder as the
That would be a shared assets over multiple pages. I wouldn't mind if we added support in Documenter for a structure like
which then maybe could be referenced with something like
which already works (and which I'm using in
Does that work? Do webservers follow symlinks in this way, ignoring the file extension?
If #64 (comment) is correct
then the difference is that "the URL for a folder load the Unless the Documenter could have such an option as well, I'd be perfectly fine with that (but it shouldn't be the default, as it limits the servers that can host the docs). I have no problem with anyone preferring the non-slash URLs on an aesthetic basis. Actually, it might be relevant to check if P.S.: Just tried |
Let's try to keep this issue focused on the fact that adding a trailing slash gives a 404 error in Vitepress. If DocumenterVitepress's links are broken on some webservers (including local servers), I imagine that's something the authors of this package would love to hear about but I request you open a new issue for that. This issue only effects folks transitioning from default Documenter.jl, and only effects them in the transition period while extant links still point to the old URLs. That said, many DoculmenterVitepress/Documenter.jl users will be transitioning from default Documenter.jl, and the transition period has an unbounded length. @asinghvi17 suggested a solution here
And I implemented and deployed it on Chairmarks here. This is a hackey solution. Would you welcome a PR that adds a redirect_trailing_slash configuration option that can be |
@goerz: I'm not sure what benefit that folder structure provides aside from avoiding namespacing issues? The asset wouldn't be loaded unless the page calls for it, in any case, and Vitepress tends to inline any included images as opposed to including them in the output. This doesn't seem to significantly impact load time (see https://beautiful.makie.org for an example). @LilithHafner: Yes that would be great! It seems to work for you already :) but how would you do the detection? One could manually check the |
lol, idk. I'll think about that. I only really care about trailing slash handling on the deployed docs, and when deploying we need access to gh-pages anyway. OTOH, it's good (necessary) to build the exact same docs locally and hosted, because otherwise what is even the point of local builds? Also, my current hack discards fragments. I'll look into that, too. |
It allows you to keep the exact URL scheme you have now (without the trailing slashes), but without requiring any hacks or server features. If you render
That is a very good point! Even if someone implemented a PR for JuliaDocs/Documenter.jl#2473 to make Documenter prefer URLs without a slash, that doesn't change existing pages, so that's going to be a problem for any project transitioning to
where the I was also worried about whether the site can be previewed locally using
Huh. I'm surprised it doesn't affect load time. I would have expected this to cause pretty huge |
Almost, but the sites without trailing slashes 301 redirect to the with slash alternatives. $ curl https://chairmarks.lilithhafner.com/v1.0.2/tutorial
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
$ curl curl https://chairmarks.lilithhafner.com/v1.1.0/tutorial
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Tutorial | Chairmarks.jl</title>
<meta name="description" content="A VitePress Site">
... (Chairmarks v1.0.2 and below uses Dcoumenter.jl without Vitepress and 1.1.0 and above uses Documenter.jl and DocumenterVitepress.jl) |
https://chairmarks.lilithhafner.com/v1.0.2/explanations (which does not use DocumenterVitepress.jl) redirects to https://chairmarks.lilithhafner.com/v1.0.2/explanations/.
The link https://chairmarks.lilithhafner.com/v1.1.0/explanations/, which uses DocumenterVitepress.jl gives a 404 error.
This caused all
https://chairmarks.lilithhafner.com/stable/.../
links I and others previously posted to break when switching to DocumenterVitepress.jl. I agree with the DocumenterVitepress.jl choice to prefer not using trailing slashes, but URLs with trailing slashes should redirect, not 404.The text was updated successfully, but these errors were encountered: