my config.ts in src/content
// 1. Import utilities from astro:contentimport { z, defineCollection } from "astro:content"; // 2. Define your collection(s) const componentsCollection = defineCollection({ type: "content", schema: z.object({ title: z.string(), }), }); // 3. Export a singlecollections object to register your collection(s) // This key should match your collection directory name in "src/content" export const collections = { components: componentsCollection, };
translate.md in src/content/components
`---
slug: "translatefddffff"
title: "345325"
Your blog post content here.`
index.astro
`---
import { getCollection } from "astro:content";
import Layout from "../layouts/Layout.astro";
const test = await getCollection("components");
<Layout title="Rex Components">
<section>
<nav>
<!-- {components.map((component: any) => <div>{component}</div>)} -->
</nav>
</section>
<main>
{test.map((post: any) => <div>{post.title}</div>)}
</main>
</Layout>
<style>
main {
color: aquamarine;
}
</style>`
All I can get from the post is either slug or body. I cannot get title. What am I doing wrong? I initially wanted to pull astro instances from components but also could not seem to get a title var, so thought it was impossible and went this route, but now... nope. Oh and post.frontmatter is undefined.