How to use Astro or NextJS <Image>
with fields.document
and fields.image
#931
-
We are struggling to setup a Keystatic Astro projects that automatically optimizes user uploaded images. The scenario: A user uploads a 5 MB screenshot in a BUT, it looks like that is not possible? Astro We managed to get a Test going with NextJS Is there a way to get this working? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey! I did some exploration on Astro Assets + Keystatic images (both The stream is very long and I get stuck on a lot of various (and unrelated) things — but essentially I got it working with a mix of:
For component blocks I used the technique described here to import all images and access the correct keys with the bracket syntax, as explained here: https://docs.astro.build/en/recipes/dynamically-importing-images/#_top Because the imports from https://www.youtube.com/watch?v=2SjCSvl8p8g You can fast forward to the end of the stream if you want to see the working solution :) I cannot share the code for it because it's based on a design that is sold on ThemeForest — but I might make a minimal reproduction or write an organised guide. |
Beta Was this translation helpful? Give feedback.
-
Using Astro assets and the component with Keystatic is sorta tricky, so I wrote a new recipe on just that for the docs website 👼 https://keystatic.com/docs/recipes/astro-images It covers uses cases for both "standalone" images (stored in frontmatter), and images inside a content component. Because both approaches are quite different 😅 |
Beta Was this translation helpful? Give feedback.
Hey!
I did some exploration on Astro Assets + Keystatic images (both
fields.image
and inside a component block) on a live stream yesterday.The stream is very long and I get stuck on a lot of various (and unrelated) things — but essentially I got it working with a mix of:
directory
property of thefields.image
to theassets
folder, , and thepublichPath
to the relative path to theassets
folder (../../assets/...
).directory
of component blocks to theassets
folder as well, but thepublicPath
to/src/assets/...
(because it needs to match Astro'sdynamic imports
withimports.meta.glob
).For component blocks I used the technique described here to import all images…