File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,6 +107,8 @@ async function getData(slug: string) {
107107
108108 return { post, relatedPosts } ;
109109 } catch ( error ) {
110+ console . error ( `[getData] Failed to get data for slug: "${ slug } "` ) ;
111+ console . error ( `[getData] Error:` , error ) ;
110112 notFound ( ) ;
111113 }
112114}
Original file line number Diff line number Diff line change @@ -56,6 +56,10 @@ export async function getPostData(slug: string): Promise<PostData> {
5656 const fileName = fileNames . find ( ( name ) => name . includes ( slug ) ) ! ;
5757
5858 if ( ! fileName ) {
59+ console . error ( `[getPostData] Post not found for slug: "${ slug } "` ) ;
60+ console . error ( `[getPostData] Posts directory: ${ postsDirectory } ` ) ;
61+ console . error ( `[getPostData] Available files (${ fileNames . length } total):` , fileNames . slice ( 0 , 10 ) ) ;
62+ console . error ( `[getPostData] Searched with: name.includes("${ slug } ")` ) ;
5963 throw new Error ( 'Post not found' ) ;
6064 }
6165
@@ -65,9 +69,19 @@ export async function getPostData(slug: string): Promise<PostData> {
6569export async function getRelatedPosts ( post : PostData ) : Promise < PostData [ ] > {
6670 const relatedPosts = post . related_posts || [ ] ;
6771
68- const posts = await Promise . all ( relatedPosts . map ( ( slug ) => getPostData ( slug ) ) ) ;
69-
70- return posts . filter ( ( item ) => ! item . unpublished ) ;
72+ const posts = await Promise . all (
73+ relatedPosts . map ( async ( slug ) => {
74+ try {
75+ return await getPostData ( slug ) ;
76+ } catch ( error ) {
77+ console . error ( `[getRelatedPosts] Failed to load related post with slug: "${ slug } " for post: "${ post . slug } "` ) ;
78+ console . error ( `[getRelatedPosts] Error:` , error ) ;
79+ return null ;
80+ }
81+ } )
82+ ) ;
83+
84+ return posts . filter ( ( item ) => item !== null && ! item . unpublished ) as PostData [ ] ;
7185}
7286
7387export function getPostByFilename ( fileName : string ) : PostData {
You can’t perform that action at this time.
0 commit comments