From 1d2bafaf908c22ee972cbb9dbb13b763d181d881 Mon Sep 17 00:00:00 2001 From: Henrique Ramos Date: Sat, 14 Dec 2024 20:58:03 -0300 Subject: [PATCH] chore: use new astro content collection API --- src/{content/config.ts => content.config.ts} | 5 +++-- src/pages/[id].astro | 21 +++++++++++++++++++ src/pages/[slug].astro | 21 ------------------- .../statex-gamedev.md | 0 4 files changed, 24 insertions(+), 23 deletions(-) rename src/{content/config.ts => content.config.ts} (67%) create mode 100644 src/pages/[id].astro delete mode 100644 src/pages/[slug].astro rename src/{content/presentations => slides}/statex-gamedev.md (100%) diff --git a/src/content/config.ts b/src/content.config.ts similarity index 67% rename from src/content/config.ts rename to src/content.config.ts index 63559f4..833a358 100644 --- a/src/content/config.ts +++ b/src/content.config.ts @@ -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 }; diff --git a/src/pages/[id].astro b/src/pages/[id].astro new file mode 100644 index 0000000..ff652d6 --- /dev/null +++ b/src/pages/[id].astro @@ -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); +--- + + + + diff --git a/src/pages/[slug].astro b/src/pages/[slug].astro deleted file mode 100644 index c9bca3c..0000000 --- a/src/pages/[slug].astro +++ /dev/null @@ -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(); ---- - - - - diff --git a/src/content/presentations/statex-gamedev.md b/src/slides/statex-gamedev.md similarity index 100% rename from src/content/presentations/statex-gamedev.md rename to src/slides/statex-gamedev.md