Closed pexeixv closed 1 year ago
You're passing a string to Image, not an image reference. Strings references are intended for remote images and as such, are passed as-is.
To use images in the frontmatter, you should use Content Collections's image()
schema.
See https://docs.astro.build/en/guides/assets/#update-content-collections-schemas for more information.
Hey @Princesseuh! Thanks for the prompt reply. I'm still not able to get it to work. How should I be declaring the image in frontmatter of markdown files?
---
titleImage: image('../assets/post-1.jpg')
---
Or something like this in the layout file?
---
import { Image, getImage } from "astro:assets";
import BlogLayout from "./BlogLayout.astro";
const {title,titleImage} = Astro.props.frontmatter
---
<BlogLayout {title}>
BlogPostLayout
<Image src={getImage(titleImage)} height={100} width={400} format="webp" alt={title}/>
<slot/>
</BlogLayout>
Both of these don't work and I just can't figure it out.
@pexeixv Did you manage to find a solution? I'm having the same issue.
Seems like this no longer works ? @Princesseuh Ive tried refering to the following docs https://docs.astro.build/en/guides/images/#images-in-content-collections
However this seems outdated as
What version of
astro
are you using?2.3.0
Are you using an SSR adapter? If so, which one?
No
What package manager are you using?
pnpm
What operating system are you using?
Windows
What browser are you using?
Brave
Describe the Bug
Trying to setup a blog website and following the following folder structure:
post-1.md
looks like this[slug].astro
looks like this:However, a broken image rendered with src
localhost:3000/assets/post-1.jpg
.Please help me out.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-36ea95?file=src/layouts/BlogPostLayout.astro
Participation