diff options
| author | Joe Carstairs <me@joeac.net> | 2024-12-24 08:42:19 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-12-24 09:00:24 +0000 |
| commit | a8efefc12f21fc3b1fe3c32898cd50d0067b93c6 (patch) | |
| tree | e2224a7dbd15c5f7c4693ca438e7d83027856a69 /src | |
| parent | 5515d5b2cce3cc43996850ff516fd1838f8fe8eb (diff) | |
Upgrades to Astro 5
Diffstat (limited to 'src')
| -rw-r--r-- | src/content.config.ts (renamed from src/content/config.ts) | 5 | ||||
| -rw-r--r-- | src/lib/newsUtils.ts | 2 | ||||
| -rw-r--r-- | src/pages/[locale]/news/[...slug].astro | 4 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/content/config.ts b/src/content.config.ts index 599c570..af3f25d 100644 --- a/src/content/config.ts +++ b/src/content.config.ts @@ -1,7 +1,8 @@ +import { glob } from 'astro/loaders'; import { defineCollection, z } from 'astro:content'; const news = defineCollection({ - type: 'content', + loader: glob({ pattern: '**/*.(md|mdx|html)', base: './src/content/news' }), schema: z.object({ title: z.string(), summary: z.string(), @@ -9,5 +10,5 @@ const news = defineCollection({ }); export const collections = { - news: 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); --- <Article title={entry.data.title}> |
