import { getReviews } from "../../../core/records"; import type { BlogPostListingPage, Ignore } from "../../../types"; import type { ExtensionOf } from "../types"; export interface Props { /** * @description Ignore specific reviews */ ignoreReviews?: Ignore; /** * @description Order By */ orderBy?: "date_asc" | "date_desc"; } /** * @title ExtensionOf BlogPostListing: Reviews * @description It can harm performance. Use wisely */ export default function reviewsExt({ ignoreReviews, orderBy, }: Props): ExtensionOf { return async (blogpostListingPage: BlogPostListingPage | null) => { if (!blogpostListingPage) { return null; } const posts = await Promise.all( blogpostListingPage.posts.map(async (post) => { const reviews = await getReviews({ post, ignoreReviews, orderBy }); return { ...post, ...reviews }; }), ); return { ...blogpostListingPage, posts }; }; }