fix(web): refresh blog content and featured post selection (#862)

This commit is contained in:
Musa 2026-04-02 09:18:19 -04:00 committed by GitHub
parent 39b430d74b
commit 76ff353c1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import { BlogSectionHeader } from "@/components/BlogSectionHeader";
import { pageMetadata } from "@/lib/metadata";
export const metadata: Metadata = pageMetadata.blog;
export const dynamic = "force-dynamic";
interface BlogPost {
_id: string;
@ -70,9 +71,40 @@ async function getBlogPosts(): Promise<BlogPost[]> {
}
}
async function getFeaturedBlogPost(): Promise<BlogPost | null> {
if (!client) {
return null;
}
const query = `*[_type == "blog" && published == true && featured == true] | order(_updatedAt desc, publishedAt desc)[0] {
_id,
title,
slug,
summary,
publishedAt,
mainImage,
mainImageUrl,
thumbnailImage,
thumbnailImageUrl,
author,
featured
}`;
try {
const post = await client.fetch(query);
return post || null;
} catch (error) {
console.error("Error fetching featured blog post:", error);
return null;
}
}
export default async function BlogPage() {
const posts = await getBlogPosts();
const featuredPost = posts.find((post) => post.featured) || posts[0];
const [posts, featuredCandidate] = await Promise.all([
getBlogPosts(),
getFeaturedBlogPost(),
]);
const featuredPost = featuredCandidate || posts[0];
const recentPosts = posts
.filter((post) => post._id !== featuredPost?._id)
.slice(0, 3);