Files
2026-09-08 23:34:42 +02:00

24 lines
794 B
TypeScript

import type { ArticleSummary, Paginated } from '#shared/types/blog'
export default defineEventHandler(async (event): Promise<Paginated<ArticleSummary>> => {
const query = getQuery(event)
const page = pageParam(query.page)
const locale = localeParam(query.lang)
const category = typeof query.category === 'string' ? query.category : null
const filter = category
? `&filters[category][slug][$eq]=${encodeURIComponent(category)}`
: ''
const response = await strapiFetch<StrapiList<ArticleSummary>>(
`/api/articles?${ARTICLE_SUMMARY_QUERY}&locale=${locale}&${pagination(page)}${filter}`
)
return {
items: response.data,
page: response.meta.pagination.page,
pageCount: response.meta.pagination.pageCount,
total: response.meta.pagination.total,
}
})