-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
fix: fromExtensions and toExtensions translation when used with baseUrl #2969
Conversation
Deploy preview for docusaurus-2 ready! Built with commit e14eadc |
Deploy preview for docusaurus-2 ready! Built with commit 0aa7011 |
Just doing some manual testing, I think I need to change the Making this a draft, it needs some more work. Sorry for the noise. |
Thanks @jknoxville :) Yeah I did not think about the base Url 😅 Tell me when it's ready for review, or if you need help |
Ok, I've updated it now and it works when using yarn build. Testing steps: First change the
Browse to It works. However, here's the weird bit:
Browse to This doesn't work for some reason, even though if you strip the '.html', it does. I haven't looked into how yarn start works yet, does anyone have any ideas why it would work with yarn build but not with yarn start? |
Ah yeah we should probably document that better. The plugin only works for a production build, by outputting some additional html files. |
I tried with
But it's not your fault anyway, so I'll merge this and we'll fix the other issue here: #2978 |
Hey @jknoxville I'm thinking about it, and I think this whole plugin should rather be baseUrl insensitive. For example, if I use The redirect I setup here will break, because all paths provided to the function will include the plugins: [
[
'@docusaurus/plugin-client-redirects',
{
fromExtensions: ['html'],
createRedirects: function (path) {
// redirect to /docs from /docs/intro,
if (path === "/docs/intro") {
return ["/docs"];
}
},
},
], This forces the user to replace Wonder if it's not better to actually remove all baseurls ahead of time. What do you think? |
Good point @slorber I think that makes a lot of sense. My main concern was just getting from and to Extensions to work, since there's no doubt that they should be baseUrl independent, but I didn't think about the other. It makes sense that you should be able to swap in any baseUrl, and any existing redirect rules will "just work" that would really be great in my opinion. The only thing that would give me slight hesitation is when you consider that a docusaurus site can live along side statically served HTML (generated without docusaurus, e.g Javadocs, appledoc etc). These files might not necessarily have the same baseUrl as the docusaurus files. It's conceivable that people would want to setup redirection rules to those URLs. But to be honest I think that seems like a rare case, and falls a bit out of the scope of this plugin IMO. It exists to redirect to docusaurus pages, not really to arbitrary paths, and if need be, the ability to redirect to paths without the baseUrl could always be added later with an option. |
Yes, anyway I don't think this plugin is suitable to write redirects from outside of its build folder. If you have /d2-site + /jekyll-site , I don't think the plugin should write redirect html files to /jekyll-site anyway. Also, I think we could work on make this plugin work even in dev with yarn start, and if we start to do such redirects, that would be impossible to add later. I've added a new issue here: #2982 |
Motivation
First of all, I LOVE @slorber 's recent PR to add redirects - thank you so much for working on it! And I think the API is great. But I think I've found a small issue with it when combined with baseUrls other than '/'.
Using, fromExtensions, when you have a baseUrl of, for example
/prefix/
, the redirect file for the docdocs/somepath
should be written todocs/somepath.html
which would be a sibling of the real file:docs/somepath
, but instead it is getting written toprefix/docs/somepath.html
.This means to hit the redirect, the baseUrl has to be included in the URL twice, so in this case the page itself would be accessible at
/prefix/docs/somepath
, and the html redirect would be accesible at/prefix/prefix/docs/somepath.html
.I've added a test case that I believe highlights what's happening, but you can repro it manually by setting a baseUrl of
/prefix/
, and then usingfromExtensions: ['html']
.Observer that the redirect file gets written to
/build/prefix/docs/page.html
, rather than/build/docs/page.html
.I've also manually tested the following redirect:
and can confirm that this works as intended, so I think it's just the translation of
fromExtensions
that is processing the baseUrl wrong.I've also made the same change in toExtensions, I think the same applies there too.
Solution
Since the translation works by mapping over all routes, and the routes already appear to have the baseUrl in them, I'm just removing that baseUrl when writing the "from" files.
Related PRs
#2793