fix: category filter by UUID and remove nav_categories from site_settings query

This commit is contained in:
achmad
2026-05-28 23:15:53 +07:00
parent bb0b2ac961
commit c4ed4a3615
3 changed files with 12 additions and 9 deletions
+2 -4
View File
@@ -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 {
+9 -4
View File
@@ -47,11 +47,17 @@ export async function getArticles(options: {
limit?: number
offset?: number
categorySlug?: string
categoryId?: string
} = {}): Promise<Article[]> {
const { limit = 12, offset = 0, categorySlug } = options
const { limit = 12, offset = 0, categorySlug, categoryId } = options
const filter: Record<string, unknown> = { 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<SiteSettings> {
'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<SiteSettings>
+1 -1
View File
@@ -37,5 +37,5 @@ export interface SiteSettings {
id: string
site_name: string
hero_article: Article | null
nav_categories: Category[]
nav_categories?: Category[]
}