mirror of
https://github.com/katanemo/plano.git
synced 2026-04-25 00:36:34 +02:00
fix(web): refresh blog content and featured post selection (#862)
This commit is contained in:
parent
39b430d74b
commit
76ff353c1e
2 changed files with 45 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue