forked from imranhsayed/nextjs-woocommerce-restapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (54 loc) · 1.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* External Dependencies.
*/
import axios from 'axios';
/**
* Internal Dependencies.
*/
import Layout from '../../src/components/layout';
import Posts from '../../src/components/posts';
import Pagination from '../../src/components/pagination';
import { HEADER_FOOTER_ENDPOINT } from '../../src/utils/constants/endpoints';
import { getPosts } from '../../src/utils/blog';
/**
* Blog Component.
*
* @param {Object} headerFooter Header Footer Data.
* @param {Object} postsData Post Data.
*/
const Blog = ( { headerFooter, postsData } ) => {
const seo = {
title: 'Blog Page',
description: 'Blog Page',
og_image: [],
og_site_name: 'React WooCommerce Theme',
robots: {
index: 'index',
follow: 'follow',
},
}
return (
<Layout headerFooter={ headerFooter || {} } seo={ seo }>
<h1>Blog</h1>
<Posts posts={ postsData?.posts_data ?? [] }/>
<Pagination pagesCount={ postsData?.page_count ?? 0 } postName="blog"/>
</Layout>
);
};
export default Blog;
export async function getStaticProps() {
const { data: headerFooterData } = await axios.get( HEADER_FOOTER_ENDPOINT );
const { data: postsData } = await getPosts();
return {
props: {
headerFooter: headerFooterData?.data ?? {},
postsData: postsData || {},
},
/**
* Revalidate means that if a new request comes to server, then every 1 sec it will check
* if the data is changed, if it is changed then it will update the
* static file inside .next folder with the new data, so that any 'SUBSEQUENT' requests should have updated data.
*/
revalidate: 1,
};
}