Skip to content

Commit acda702

Browse files
committed
fix: empty status
1 parent ccc3cbb commit acda702

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

apps/docs/app/(home)/blog/[slug]/page.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ const WORD_SPLIT_REGEX = /\s+/;
2121
export const revalidate = 300;
2222

2323
export async function generateStaticParams() {
24-
const { posts } = await getPosts();
25-
return posts.map((post) => ({
26-
slug: post.slug,
27-
}));
24+
try {
25+
const result = await getPosts();
26+
if ('error' in result) {
27+
return [];
28+
}
29+
return result.posts.map((post) => ({
30+
slug: post.slug,
31+
}));
32+
} catch {
33+
return [];
34+
}
2835
}
2936

3037
interface PageProps {
@@ -39,7 +46,7 @@ export async function generateMetadata({
3946

4047
try {
4148
const data = await getSinglePost(slug);
42-
if (!data?.post) {
49+
if ('error' in data || !data?.post) {
4350
return { title: 'Not Found | Databuddy' };
4451
}
4552

apps/docs/app/(home)/blog/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ function BlogPostCard({ post }: { post: Post }) {
169169
}
170170

171171
export default async function BlogPage() {
172-
const { posts } = await getPosts();
172+
const result = await getPosts();
173+
const posts = 'error' in result ? [] : result.posts;
173174
const sortedPosts = [...posts].sort(
174175
(a, b) =>
175176
new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime()

0 commit comments

Comments
 (0)