As an example, I have an Astro app with a collection /collections/artworks
where each artwork
specifices a cover image via the frontmatter cover: '../assets/artworks/1-hello/cover.png
- the file lies at /src/assets/artworks/1-hello/cover.png
. I am trying to use Astro's asset support.
Then in my template, I am looping through all the artworks and have <Image width={400} src={artwork.data.cover} alt={artwork.data.coverAlt} />
which does not work and fails to find the file.
Trying to import it inline seems to fail <Image width={400} src={import(artwork.data.cover)} alt={artwork.data.coverAlt} />
with the error "Received unsupported format undefined
from undefined
", assuming that it's just not resolving.
However, if I import the image explicitly with the same path as specified in the markdown, it works:
import cover from "../assets/artworks/1-hello/cover.png"
<Image src={cover} ... />
How can I loop through a collection and dynamically import images specified in the markdown accordingly?