chore: use new astro content collection API

This commit is contained in:
Henrique Ramos 2024-12-14 20:58:03 -03:00
parent 7a7c6ab456
commit 1d2bafaf90
4 changed files with 24 additions and 23 deletions

View File

@ -1,7 +1,8 @@
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders"; // Not available with legacy API
const presentations = defineCollection({
const slides = defineCollection({
loader: glob({ pattern: "**/*.md", base: "./src/slides" }),
schema: z.object({
title: z.string(),
description: z.string(),
@ -10,4 +11,4 @@ const presentations = defineCollection({
}),
});
export const collections = { presentations };
export const collections = { slides };

21
src/pages/[id].astro Normal file
View File

@ -0,0 +1,21 @@
---
import SlideLayout from "@layouts/SlideLayout.astro";
import { getCollection, render } from "astro:content";
export const getStaticPaths = async () =>
(await getCollection("slides")).map((slide) => ({
params: { id: slide.id },
props: { slide },
}));
const { slide } = Astro.props;
const { Content } = await render(slide);
---
<SlideLayout
title={slide.data.title}
authors={slide.data.authors}
description={slide.data.description}
>
<Content />
</SlideLayout>

View File

@ -1,21 +0,0 @@
---
import SlideLayout from "@layouts/SlideLayout.astro";
import { getCollection } from "astro:content";
// 1. Generate a new path for every collection entry
export const getStaticPaths = async () =>
(await getCollection("presentations")).map((presentation) => ({
params: { slug: presentation.slug },
props: { presentation },
}));
const { presentation } = Astro.props;
const { Content } = await presentation.render();
---
<SlideLayout
title={presentation.data.title}
authors={presentation.data.authors}
description={presentation.data.description}
>
<Content />
</SlideLayout>