chore: use new astro content collection API
This commit is contained in:
parent
7a7c6ab456
commit
1d2bafaf90
@ -1,7 +1,8 @@
|
|||||||
import { defineCollection, z } from "astro:content";
|
import { defineCollection, z } from "astro:content";
|
||||||
import { glob } from "astro/loaders"; // Not available with legacy API
|
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({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
description: 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
21
src/pages/[id].astro
Normal 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>
|
||||||
@ -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>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user