Hey, I am building my first Astro site and have just started to use Content Collections to build a “meet the family page” - each family member's associated data is managed in the YAML file in content. The associated data includes a bio image.
I am getting the following error:
Image's and getImage's src parameter must be an imported image or an URL, it cannot be a string filepath. Received @images/member-1.jpeg.
The below code/config is correct per astro docs. Any help pointers will be appreciated.
content.ts
import { z, defineCollection } from "astro:content";
export const collections = {
familymembers: defineCollection({
type: "data",
schema: ({ image }) =>
z.object({
name: z.string(),
funName: z.string(),
bio: z.string(),
bioImage: image(),
}),
}),
};
Member-1.yaml
name: member-1
funName: member
bio: Help my name is ….
bioImage: "@images/member-1.jpeg"
Profile Pic Component (profile.astro)
---
import { Image } from "astro:assets";
import { getEntry, type CollectionEntry } from "astro:content";
type Props = {
tjpMember: CollectionEntry<"familymembers">;
};
const { tjpMember } = Astro.props;
const { name, funName, bio, bioImage} = tjpMember.data;
console.log(bioImage)
---
<div class="flex mt-12">
<div class=" flex items-center h-full ">
<div class="bg-gradient-to-r from-stone-100 to-neutral-100 via-gray-100 shadow-xl shadow-gray-300 p-4 rounded-lg max-w-xs -rotate-2">
<div class="relative">
<!-- The photo -->
<Image src={bioImage}
height={600}
width={600}
alt=" "
>
</div>
</div>
</div>
Folder Structure
src-->assets-->images
src-->components-->profile.astro
src-->content-->familymembers-->member-1.yaml
src-->content-->content.js