fix: category filter by UUID and remove nav_categories from site_settings query
This commit is contained in:
+9
-4
@@ -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
@@ -37,5 +37,5 @@ export interface SiteSettings {
|
||||
id: string
|
||||
site_name: string
|
||||
hero_article: Article | null
|
||||
nav_categories: Category[]
|
||||
nav_categories?: Category[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user