From a8efefc12f21fc3b1fe3c32898cd50d0067b93c6 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 24 Dec 2024 08:42:19 +0000 Subject: Upgrades to Astro 5 --- src/content.config.ts | 14 ++++++++++++++ src/content/config.ts | 13 ------------- src/lib/newsUtils.ts | 2 +- src/pages/[locale]/news/[...slug].astro | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 src/content.config.ts delete mode 100644 src/content/config.ts (limited to 'src') diff --git a/src/content.config.ts b/src/content.config.ts new file mode 100644 index 0000000..af3f25d --- /dev/null +++ b/src/content.config.ts @@ -0,0 +1,14 @@ +import { glob } from 'astro/loaders'; +import { defineCollection, z } from 'astro:content'; + +const news = defineCollection({ + loader: glob({ pattern: '**/*.(md|mdx|html)', base: './src/content/news' }), + schema: z.object({ + title: z.string(), + summary: z.string(), + }), +}); + +export const collections = { + news, +}; diff --git a/src/content/config.ts b/src/content/config.ts deleted file mode 100644 index 599c570..0000000 --- a/src/content/config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineCollection, z } from 'astro:content'; - -const news = defineCollection({ - type: 'content', - schema: z.object({ - title: z.string(), - summary: z.string(), - }), -}); - -export const collections = { - news: news, -}; diff --git a/src/lib/newsUtils.ts b/src/lib/newsUtils.ts index bffc7d6..233fdcf 100644 --- a/src/lib/newsUtils.ts +++ b/src/lib/newsUtils.ts @@ -25,7 +25,7 @@ export function getHref(newsItem: CollectionEntry<'news'>) { export function getSlug(newsItem: CollectionEntry<'news'>) { const toLowerCase = (s: string) => s.toLowerCase(); const matchLocales = new RegExp(`(${locales.map(toLowerCase).join('|')})/`); - return newsItem.slug.replace(matchLocales, ''); + return newsItem.id.replace(matchLocales, ''); } export function isNewsItemInLocale(newsItem: CollectionEntry<'news'>, locale: Locale) { diff --git a/src/pages/[locale]/news/[...slug].astro b/src/pages/[locale]/news/[...slug].astro index a24e65a..4585cf2 100644 --- a/src/pages/[locale]/news/[...slug].astro +++ b/src/pages/[locale]/news/[...slug].astro @@ -1,6 +1,6 @@ --- import Article from '$layouts/Article.astro'; -import { getCollection } from 'astro:content'; +import { getCollection, render } from 'astro:content'; import { getLocale, getSlug } from '$lib/newsUtils'; export async function getStaticPaths() { @@ -14,7 +14,7 @@ export async function getStaticPaths() { } const { entry } = Astro.props; -const { Content } = await entry.render(); +const { Content } = await render(entry); ---
-- cgit v1.2.3