forked from craigary/nobelium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (31 loc) · 1019 Bytes
/
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
import { clientConfig } from '@/lib/server/config'
import Container from '@/components/Container'
import BlogPost from '@/components/BlogPost'
import Pagination from '@/components/Pagination'
import { getAllPosts } from '@/lib/notion'
import { useConfig } from '@/lib/config'
export async function getStaticProps () {
const posts = await getAllPosts({ includePages: false })
const postsToShow = posts.slice(0, clientConfig.postsPerPage)
const totalPosts = posts.length
const showNext = totalPosts > clientConfig.postsPerPage
return {
props: {
page: 1, // current page is 1
postsToShow,
showNext
},
revalidate: 1
}
}
export default function Blog ({ postsToShow, page, showNext }) {
const { title, description } = useConfig()
return (
<Container title={title} description={description}>
{postsToShow.map(post => (
<BlogPost key={post.id} post={post} />
))}
{showNext && <Pagination page={page} showNext={showNext} />}
</Container>
)
}