@@ -10,14 +10,16 @@ import axios from 'axios';
10
10
*/
11
11
import Layout from '../../src/components/layout' ;
12
12
import { FALLBACK , handleRedirectsAndReturnData } from '../../src/utils/slug' ;
13
- import { sanitize } from '../../src/utils/miscellaneous' ;
13
+ import { getFormattedDate , sanitize } from '../../src/utils/miscellaneous' ;
14
14
import { HEADER_FOOTER_ENDPOINT } from '../../src/utils/constants/endpoints' ;
15
15
import { getPost , getPosts } from '../../src/utils/blog' ;
16
16
import Image from '../../src/components/image' ;
17
17
import PostMeta from '../../src/components/post-meta' ;
18
18
19
19
const Post = ( { headerFooter, postData } ) => {
20
20
const router = useRouter ( ) ;
21
+
22
+ console . log ( 'postData' , postData ) ;
21
23
22
24
/**
23
25
* If the page is not yet generated, this will be displayed
@@ -28,20 +30,21 @@ const Post = ( { headerFooter, postData } ) => {
28
30
}
29
31
30
32
return (
31
- < Layout headerFooter = { headerFooter || { } } seo = { null } >
33
+ < Layout headerFooter = { headerFooter || { } } seo = { postData ?. yoast_head_json ?? { } } >
32
34
< div className = "mb-8 w-4/5 m-auto" >
33
35
< figure className = "overflow-hidden mb-4" >
34
36
< Image
35
- sourceUrl = { postData ?. attachment_image ?. img_src ?. [ 0 ] ?? '' }
36
- title = { postData ?. title ?? '' }
37
- width = { postData ?. attachment_image ?. img_src ?. [ 1 ] ?? ' 600' }
38
- height = { postData ?. attachment_image ?. img_src ?. [ 2 ] ?? ' 400' }
37
+ sourceUrl = { postData ?. _embedded [ 'wp:featuredmedia' ] ?. [ 0 ] ?. source_url ?? '' }
38
+ title = { postData ?. title ?. rendered ?? '' }
39
+ width = " 600"
40
+ height = " 400"
39
41
layout = "fill"
40
42
containerClassNames = "w-full h-600px"
41
43
/>
42
44
</ figure >
43
- < PostMeta post = { postData } />
44
- < div dangerouslySetInnerHTML = { { __html : sanitize ( postData ?. content ?? '' ) } } />
45
+ < PostMeta date = { getFormattedDate ( postData ?. date ?? '' ) } authorName = { postData ?. _embedded ?. author ?. [ 0 ] ?. name ?? '' } />
46
+ < h1 dangerouslySetInnerHTML = { { __html : sanitize ( postData ?. title ?. rendered ?? '' ) } } />
47
+ < div dangerouslySetInnerHTML = { { __html : sanitize ( postData ?. content ?. rendered ?? '' ) } } />
45
48
</ div >
46
49
</ Layout >
47
50
) ;
@@ -51,13 +54,13 @@ export default Post;
51
54
52
55
export async function getStaticProps ( { params } ) {
53
56
const { data : headerFooterData } = await axios . get ( HEADER_FOOTER_ENDPOINT ) ;
54
- const { data : postData } = await getPost ( params ?. slug ?? '' ) ;
55
- // params?.slug ?? ''
57
+ // const { data: postData } = await getPost( params?.slug ?? '' );
58
+ const postData = await getPost ( params ?. slug ?? '' ) ;
56
59
57
60
const defaultProps = {
58
61
props : {
59
62
headerFooter : headerFooterData ?. data ?? { } ,
60
- postData : postData ?. post_data ?? { }
63
+ postData : postData ?. [ 0 ] ?? { }
61
64
} ,
62
65
/**
63
66
* Revalidate means that if a new request comes to server, then every 1 sec it will check
@@ -67,7 +70,7 @@ export async function getStaticProps( { params } ) {
67
70
revalidate : 1 ,
68
71
} ;
69
72
70
- return handleRedirectsAndReturnData ( defaultProps , postData , 'post_data' ) ;
73
+ return handleRedirectsAndReturnData ( defaultProps , postData ) ;
71
74
}
72
75
73
76
/**
0 commit comments