Skip to content

Commit a1cec2a

Browse files
committed
✨ feat: add 'Next Page →' and '← Previous Page' links to blog
1 parent 0601e94 commit a1cec2a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/templates/blog-post-list.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ import MetaInfo from '../components/meta-info';
99
import Page from '../components/page';
1010
import Lead from '../components/lead';
1111
import theme from '../theme';
12+
import Button from '../components/button';
1213

13-
function Blog({ data }) {
14+
function Blog({ data, pageContext }) {
15+
const { currentPage, limit, numPages, skip } = pageContext
16+
const isFirst = currentPage === 1
17+
const isLast = currentPage === numPages
18+
const prevPage = currentPage - 1 === 1 ? "" : (currentPage - 1).toString()
19+
const nextPage = (currentPage + 1).toString()
1420
return (
1521
<Layout>
1622
<Helmet>
@@ -36,7 +42,25 @@ function Blog({ data }) {
3642
<Lead>{node.frontmatter.description}</Lead>
3743
</article>
3844
))}
39-
{/* TODO: pagination */}
45+
<div css={css`
46+
display: flex;
47+
justify-content: space-between;
48+
`}>
49+
{!isFirst && (
50+
<Button href={`/blog/${prevPage}`} rel="prev" className='primary' css={css`
51+
margin: ${theme.space[4]} 0;
52+
`}>
53+
← Previous Page
54+
</Button>
55+
)}
56+
{!isLast && (
57+
<Button href={`/blog/${nextPage}`} rel="next" className='primary' css={css`
58+
margin: ${theme.space[4]} 0;
59+
`}>
60+
Next Page →
61+
</Button>
62+
)}
63+
</div>
4064
</Container>
4165
</Page>
4266
</Layout>

0 commit comments

Comments
 (0)