-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
feat: better errors for images #8536
Conversation
🦋 Changeset detectedLatest commit: 1286af2 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const resolvedOptions: ImageTransform = { | ||
...options, | ||
src: | ||
typeof options.src === 'object' && 'then' in options.src | ||
? (await options.src).default | ||
? (await options.src).default ?? (await options.src) |
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.
This is a small behaviour change to support using non-eager import.meta.glob
better. Saw some users confused that they couldn't pass the result of it to Image without awaiting multiple times and calling multiple functions in some cases. This was particularly relevant in MDX where you can't await everything the same way as in Astro files
const boldRegex = /\*\*(.+)\*\*/gm; | ||
const urlRegex = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; | ||
const urlRegex = / (\b(https?|ftp):\/\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; |
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.
A small regression fix in this regex. I changed it not too long ago and it broke some links in subtle ways, this fixes that
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.
Docs look good! Thanks @Princesseuh !
This PR blocks production on my env as I rely on string based filepath for Minimum example: const { title, description, heroImage = "@assets/blog/introducing-astro.jpg" } = Astro.props;
const { src }= await getImage({
src: heroImage, width: 640, height: 426,
alt: ''
});
const socialImageURL = new URL(src, Astro.site); <meta property="og:image" content={socialImageURL} /> |
How did this work before? Before this PR this would've ended up being an invalid path at build time anyway. |
Not at all. Basically I would pass |
Hmm, |
I'll try to make a min repro in a few days 👍 |
Alright, I found a better way to deal with this stuff. Sorry for any inconvenience. Keep up the good work 👍 |
can you tell me how? I'm struggling to making og:image work with cover images saved in the src folder but can't figure it out |
Changes
Users makes some understandable mistakes around using
<Image />
:import.meta.glob
This PR adds better documentation and error messages around these cases to better inform users on the proper way to use
<Image />
. Hopefully it'll help!This PR also includes a small styling change to the overlay, as informed by Mark.
Testing
Tested manually the new messages, we have tests for errors otherwise already
Docs
Some of this is docs!
/cc @withastro/maintainers-docs