-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Preserve relative path when switching from latest version of the documentation to an older version #22536
Conversation
Deploy preview for kubernetes-io-master-staging ready! Built with commit 7bc5ee0 https://deploy-preview-22536--kubernetes-io-master-staging.netlify.app |
/assign @xiangpengzhao |
/lgtm |
/area web-development I tested this by:
Based on the results of #4 above, I compared this to the live site's existing behavior for old versions with untranslated content. Because the live site always redirects to the homepage from the version drop-down, this is a non-issue. @brianpursley: Do you think there's any way we can handle the 404's found while testing and redirect them to the version's landing page? If the answer is "no" that's fine too, I think this is still a valuable contribution regardless. P.S., I think this would be a great contribution to upstream Docsy and you should totally do it! |
Related/probably closes: #16740 |
@celestehorgan Thanks for pointing that out... I see what you are saying. This change will definitely bring this problem to light. Even though it is not exactly a new problem, it would not occur currently, because it does not preserve the relative page when switching versions. Let me take a look at it and I'll take a look at Docsy too and see what can be done about it. |
@brianpursley If it's not easily solvable, then I'd rather post this issue to #sig-docs-maintainers and let the group decide whether or not to accept this change with the caveats found during testing. tl;dr don't spend too many cycles on this. |
@celestehorgan As you hinted at, it seems like this is going to be a little tricky. The problem is that it is unknown if the relative path is going to 404 or not at the time when the version switch is made, only after it navigates can it be known whether that page exists or not (because each version is a different site altogether I believe). I thought about one way it could work is the version switcher could add a querystring, something like I notice that 404.html only seems to be in English. I wonder if we could approach this problem from another angle and accept the fact that sometimes a page won't exist when switching versions, but implement language-specific 404 pages so that it is a better experience when it occurs. Also, strangely, when I run the site locally, I don't get the custom 404 page at all, so something else must be handling the 404s when it is deployed. I admit, I'm not too familiar with the inner workings of the documentation website. |
How about JavaScript that sends a HEAD request for the target version's page and, if it's a 404, lops off the path to take you to the top of the site instead? (that's fine by me to add later, BTW) |
/lgtm |
If we added some JavaScript to the 404 page that had access to |
I like this idea and I was going to try something like below, but CORS blocks it when testing locally, and I think would also block it in production because each version is on a different subdomain
I guess we could set CORS headers in
Any thoughts on setting CORS? Would that be OK or too much trouble? EDIT: Alternatively, maybe your other idea about updating the 404 page will work for switching versions too.... detect a version switch and then redirect to the home page although the redirect might be a little annoying if it messes up the back button. I'll give that a try locally and see how it works though. EDIT 2: Ah, maybe this would prevent the redirect from causing back button issues... |
Allowing HEAD and in fact GET from everywhere seems fine to me. I'd like a second opinion before it gets a solid thumbs up, in case I'm missing something. |
Adding this script to the 404.html in layouts seems to work and would not require a cors change:
If checks referrer against two regular expressions to figure out if you came from a different version of the documentation...
On the plus side, this would not require a cors change On the minus side, if 404.html is localized, it might need to be refactored to make it more reusable. Maybe hugo has a way to reuse this or we could put it in a js file I guess. Not sure what is best. Anyway, I'm open to either approach either make the pre-navigation HEAD request to check, or update the 404 to detect the situation. |
Yep! Partials or shortcodes. Probably a partial. |
OK I just pushed a new version with a partial used in 404.html to redirect version switch 404s to the site root. |
👀 |
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.
/lgtm
I tested this by:
Expected/Actual results: The redirect works ✅
Expected/Actual results: The redirect works ✅
Expected/Actual results: The 404 redirect works ✅
Expected/Actual results: The 404 redirect works ✅
Expected/Actual results: The page hits the 404, no regressions were introduced ✅ This PR behaves as expected and does not introduce any regressions. As such, it's approved, but with a hold because we're in repository freeze for the 1.19 release :) /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: celestehorgan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Fixes #22497