File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
apps/docs/app/(home)/blog Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,17 @@ const WORD_SPLIT_REGEX = /\s+/;
2121export const revalidate = 300 ;
2222
2323export 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
3037interface 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
Original file line number Diff line number Diff line change @@ -169,7 +169,8 @@ function BlogPostCard({ post }: { post: Post }) {
169169}
170170
171171export 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 ( )
You can’t perform that action at this time.
0 commit comments