diff --git a/app/[category]/page.tsx b/app/[category]/page.tsx index 79f9d0f..ff81705 100644 --- a/app/[category]/page.tsx +++ b/app/[category]/page.tsx @@ -40,10 +40,8 @@ export default async function CategoryPage({ params }: Props) { let articles: import('@/lib/types').Article[] = [] try { - const [cat, arts] = await Promise.all([ - getCategoryBySlug(categorySlug), - getArticles({ categorySlug, limit: 24 }), - ]) + const cat = await getCategoryBySlug(categorySlug) + const arts = cat ? await getArticles({ categoryId: cat.id, limit: 24 }) : [] category = cat articles = arts } catch { diff --git a/lib/directus.ts b/lib/directus.ts index 78e3f39..4bd8f97 100644 --- a/lib/directus.ts +++ b/lib/directus.ts @@ -47,11 +47,17 @@ export async function getArticles(options: { limit?: number offset?: number categorySlug?: string + categoryId?: string } = {}): Promise { - const { limit = 12, offset = 0, categorySlug } = options + const { limit = 12, offset = 0, categorySlug, categoryId } = options const filter: Record = { status: { _eq: 'published' } } - if (categorySlug) { - filter['category'] = { slug: { _eq: categorySlug } } + if (categoryId) { + filter['category'] = { _eq: categoryId } + } else if (categorySlug) { + const cat = await getCategoryBySlug(categorySlug) + if (cat) { + filter['category'] = { _eq: cat.id } + } } return getClient().request( readItems('articles', { @@ -129,7 +135,6 @@ export async function getSiteSettings(): Promise { 'hero_article.id', 'hero_article.title', 'hero_article.slug', 'hero_article.excerpt', 'hero_article.featured_image', 'hero_article.category.slug', 'hero_article.category.name', - 'nav_categories.id', 'nav_categories.name', 'nav_categories.slug', ], }) ) as Promise diff --git a/lib/types.ts b/lib/types.ts index f31c159..57ec863 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -37,5 +37,5 @@ export interface SiteSettings { id: string site_name: string hero_article: Article | null - nav_categories: Category[] + nav_categories?: Category[] }