jonbio/pages/blog.js

36 lines
977 B
JavaScript
Raw Normal View History

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
export const POSTS_PER_PAGE = 10
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)
const pagination = {
currentPage: 1,
2021-05-29 16:08:22 +08:00
totalPages: Math.ceil(posts.length / POSTS_PER_PAGE),
}
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-01-10 17:35:37 +08:00
<PageSeo
2021-01-10 14:32:35 +08:00
title={`Blog - ${siteMetadata.author}`}
2021-01-09 17:50:45 +08:00
description={siteMetadata.description}
2021-01-10 17:35:37 +08:00
url={`${siteMetadata.siteUrl}/blog`}
2021-01-09 17:50:45 +08:00
/>
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
</>
)
}