2021-01-09 17:50:45 +08:00
|
|
|
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
|
|
|
import siteMetadata from '@/data/siteMetadata'
|
|
|
|
import ListLayout from '@/layouts/ListLayout'
|
2021-01-10 17:35:37 +08:00
|
|
|
import { PageSeo } from '@/components/SEO'
|
2021-01-09 17:50:45 +08:00
|
|
|
|
2021-06-22 23:51:41 +08:00
|
|
|
export const POSTS_PER_PAGE = 5
|
2021-05-26 16:56:19 +03:00
|
|
|
|
2021-01-09 17:50:45 +08:00
|
|
|
export async function getStaticProps() {
|
2021-05-29 16:08:22 +08:00
|
|
|
const posts = await getAllFilesFrontMatter('blog')
|
|
|
|
const initialDisplayPosts = posts.slice(0, POSTS_PER_PAGE)
|
2021-05-26 16:56:19 +03:00
|
|
|
const pagination = {
|
|
|
|
currentPage: 1,
|
2021-05-29 16:08:22 +08:00
|
|
|
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
|
2021-05-26 16:56:19 +03:00
|
|
|
}
|
2021-01-09 17:50:45 +08:00
|
|
|
|
2021-05-29 16:08:22 +08:00
|
|
|
return { props: { initialDisplayPosts, posts, pagination } }
|
2021-01-09 17:50:45 +08:00
|
|
|
}
|
|
|
|
|
2021-05-29 16:08:22 +08:00
|
|
|
export default function Blog({ posts, initialDisplayPosts, pagination }) {
|
2021-01-09 17:50:45 +08:00
|
|
|
return (
|
|
|
|
<>
|
2021-06-22 23:51:41 +08:00
|
|
|
<PageSeo title={`Blog - ${siteMetadata.author}`} description={siteMetadata.description} />
|
2021-05-29 16:08:22 +08:00
|
|
|
<ListLayout
|
|
|
|
posts={posts}
|
|
|
|
initialDisplayPosts={initialDisplayPosts}
|
|
|
|
pagination={pagination}
|
|
|
|
title="All Posts"
|
|
|
|
/>
|
2021-01-09 17:50:45 +08:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|