Adding baseUrl to feed links.#745
Conversation
This fixes a bug reported in jest: jestjs/jest#6418
|
Deploy preview for docusaurus-preview ready! Built with commit 2505d4a |
|
Actually, perhaps I should add a test for this. I think this PR will add 2 slashes when baseUrl is |
|
Yeah, the https://deploy-preview-745--docusaurus-preview.netlify.com/ atom.xml link has a double slash. So I feel like even though that "works", it's not good enough. Not sure if it's too much overhead to add some "url normalization" or if that's just a maintenance nightmare (and opens a can of worms). I could add some smarter string concatenation here (like checking whether to use |
|
You can just use a regex to replace the ending slash and still use /blog/atom.xml |
|
@endiliey - good call. I'm just going to use a variable for this: |
|
I made a mountain out of a molehill, but I think it works now. |
|
@skratchdot Nice! Maybe we can expand the use of your variable throughout the rest of the file? For example, I bet you would run into the same problem with Also, I wonder if another alternative could have been using |
|
@JoelMarcey I think using |
|
I always forget about Windows 🤣 |
|
@skratchdot Btw, If you prefer just to leave the PR as-is, I can make the additional updates to use your new variable as well in another PR. |
|
I'm happy to make a change, but was worried about the other places since the final string concatenation part of those instances are variables. For instance: Also, I had considered using something like node's WIth all that said, I'm happy with the PR as is, but am also willing to make changes (as long as they don't introduce too much risk). |
|
I wonder if we should use a package like this? https://www.npmjs.com/package/url-join instead have a built-in package take care of it for us?
Assuming we don't use a package, you could manually add the slash in the |
endiliey
left a comment
There was a problem hiding this comment.
Just checked url-join, it's quite handy. Leaving it to @JoelMarcey & @yangshun if we want to use such package.
From my understanding, we always expect baseUrl to end with a slash actually. There's a lot of other codes that will break if it's not.
Maybe let's use something like websiteUrl or siteUrl instead of feedBase to promote reusability & common name.
E.g: siteUrl = https://facebook.github.io/jest/
|
I played with and it seemed to work. The only worry I would have is the additional overhead/bytes of a new package (but the source doesn't seem that big). I agree, if we start using the variable for more, then it should be renamed to something like 3 other thoughts:
Would you all be okay with me trying to "fix" this PR by using the method I mentioned in my "thought # 2" above? Then we could address other issues/thoughts in a separate PR. |
|
I'm ok with your thought #2. Most baseUrl always end with slash (never seen one without) Even when user create new docusaurus project, we guided them to do so |
|
@skratchdot Hi! In general, I am not too concerned about adding another package to use within the Docusaurus core. Any affect is really only seen in development -- since the output of Docusaurus is raw html -- and in this case, I don't think the development impact would be very large. So I generally go with the question of whether the package will make Docusaurus better and more correct vs. the maintainers having to roll something themselves to do the same thing. If we think |
|
@endiliey - Thanks for those examples! I just updated the code. I'll confirm the example site once it's rebuilt. |
|
This LGTM. I'll leave it to @JoelMarcey to approve. Thanks for the PR, It made me realize we lack meta description tag which is crucial for SEO. Might file an issue for that 😄 |
JoelMarcey
left a comment
There was a problem hiding this comment.
I think I am good with this. Just one question inline.
| // ensure the siteUrl variable ends with a single slash | ||
| const siteUrl = | ||
| (this.props.config.url + this.props.config.baseUrl).replace(/\/+$/, '') + | ||
| '/'; |
There was a problem hiding this comment.
So this won't cause a possible double ending // when we use it below?
For example, siteUrl always ends with a single slash. Could this.props.config.ogImage start with a single slash, causing a // in line 51?
Just wanting to make sure we are still good there.
JoelMarcey
left a comment
There was a problem hiding this comment.
I think even if the answer to my question was true, it should still work. Long term, maybe let's see about using url-join anyway.
Motivation
This hopefully fixes a bug reported in jest:
jestjs/jest#6418
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
I considered adding a test for this, but there didn't appear to be any for this file. I can add them if you would like. For the time being, all I did was use the following as a smoke test:
og:imageurl works: https://facebook.github.io/jest/img/opengraph.pngatom.xmlurl is incorrect: https://facebook.github.io/blog/atom.xmlRelated PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)