From 44810a5b66888a3e82431bb6a24d6f38487b22b9 Mon Sep 17 00:00:00 2001 From: Spherrrical Date: Thu, 2 Apr 2026 06:14:57 -0700 Subject: [PATCH] fix(web): refresh blog content and featured post selection --- apps/www/src/app/blog/page.tsx | 36 ++++++++++++++++++++++++++++++++-- apps/www/src/lib/sanity.ts | 15 ++++++++++---- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/apps/www/src/app/blog/page.tsx b/apps/www/src/app/blog/page.tsx index 93e5d271..65561f0c 100644 --- a/apps/www/src/app/blog/page.tsx +++ b/apps/www/src/app/blog/page.tsx @@ -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 { } } +async function getFeaturedBlogPost(): Promise { + 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); diff --git a/apps/www/src/lib/sanity.ts b/apps/www/src/lib/sanity.ts index d5a26217..b87b2184 100644 --- a/apps/www/src/lib/sanity.ts +++ b/apps/www/src/lib/sanity.ts @@ -2,9 +2,15 @@ import { createClient } from "@sanity/client"; import imageUrlBuilder from "@sanity/image-url"; import type { SanityImageSource } from "@sanity/image-url/lib/types/types"; -const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID; -const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET; -const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION; +const projectId = + process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || + "71ny25bn"; +const dataset = + process.env.NEXT_PUBLIC_SANITY_DATASET || + "production"; +const apiVersion = + process.env.NEXT_PUBLIC_SANITY_API_VERSION || + "2025-01-01"; export const hasSanityConfig = Boolean(projectId && dataset && apiVersion); @@ -13,7 +19,8 @@ export const client = hasSanityConfig projectId, dataset, apiVersion, - useCdn: true, // Set to false if statically generating pages, using ISR or using the on-demand revalidation API + // Keep blog/admin updates visible immediately after publishing. + useCdn: false, }) : null;