-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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(blog): apply baseUrl to relative image in blog authors #10440
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Size Change: -951 B (-0.01%) Total Size: 11.6 MB ℹ️ View Unchanged
|
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.
Fix is kinda ugly, baseUrl things are a bit of a pain
Not sure to understand what you mean here. What is ugly and what is a pain?
moreover now we have 2 separate datas, the one from
getAuthorsMap
inloadContent
andauthorsMap
incontentLoaded
What is the problem? We need to define at which step this baseUrl gets applied. There are many possible solutions, including applying later when creating the props.
I think applying it earlier in authors map is fine and consistent with the way we deal with baseUrl in many places currently.
Deprecating / removing inline authors would simplify things
We don't really plan to do that 😅
@@ -28,7 +28,7 @@ function normalizeImageUrl({ | |||
imageURL: string | undefined; | |||
baseUrl: string; | |||
}) { | |||
return imageURL?.startsWith('/') |
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 the goal is a double application, there's probably a better solution.
Remember that:
- The user might use baseUrl
/blog/
- The user might put files in
/static/blog/
- An author image hosted at
/blog/blog/authorImage.png
is perfectly valid
I think I'd prefer to not have this extra condition
In the past (useBaseUrl
hook) it has been annoying because some users will use baseUrl /docs/
or /blog/
and duplicate paths like /docs/docs/someImage.png
or /blog/blog/someImage.png
should be allowed
I'd like to have a unit test ensuring that we actually allow /baseUrl/baseUrl/img/ozaki.jpg
What we want is to not apply the baseUrl if the author is a global author (ie it has a key
).
My suggestion:
function toAuthor(frontMatterAuthor: BlogPostFrontMatterAuthor): Author {
const author = {
// Author def from authorsMap can be locally overridden by front matter
...getAuthorsMapAuthor(frontMatterAuthor.key),
...frontMatterAuthor,
};
return {
...author,
key: author.key ?? null,
page: author.page ?? null,
// global author images have already been normalized
imageURL: author.key ? author.imageURL : normalizeImageUrl({imageURL: author.imageURL, baseUrl}),
};
}
The unit tests should clearly cover this case
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'd like to have a unit test ensuring that we actually allow
/baseUrl/baseUrl/img/ozaki.jpg
I don't think that's a good idea. No one should be producing these URLs on purpose. See my opinion in #6294 too.
If a URL is /image.png
, it should be come /baseURL/image.png
, but /baseURL/image.png
should stay that way.
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.
@Josh-Cena it's important that urls are portable, and that we can later use React Router built-in basename which will not have this deduplication logic (although it won't apply to images but only links)
You'll see for yourself that existing sites have /docs/docs
already, whether it makes sense to you or not: https://eclipse-muto.github.io/docs/docs/muto
I know you want devs to be explicit in this case and write links such as /docs/docs/muto
, but this means this link is not "baseUrl" portable anymore.
Another case: the same sites at Meta are deployed in different fashions for public/internal usage, with/without baseUrl.
I'd like to discourage the usage of links that include the baseUrl to maximize portability.
packages/docusaurus-plugin-content-blog/src/__tests__/authorsMap.test.ts
Outdated
Show resolved
Hide resolved
packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts
Outdated
Show resolved
Hide resolved
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 👍 thanks
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Motivation
Fix #10434
Test Plan
unit tests
Test links
Deploy preview: https://deploy-preview-10440--docusaurus-2.netlify.app/