diff --git a/src/templates/index.js b/src/templates/index.js index 7731fd0..ee02808 100644 --- a/src/templates/index.js +++ b/src/templates/index.js @@ -30,7 +30,7 @@ const BlogPost = ({ node }) => { class IndexPage extends React.Component { render() { - const { nextPath, prevPath, pageID } = this.props.pageContext; + const { nextPath, prevPath, firstPath, lastPath, pageID } = this.props.pageContext; const posts = this.props.data.allContentfulPost.edges; console.log(this.props.pageContext); @@ -45,6 +45,31 @@ class IndexPage extends React.Component {
+
+ {firstPath && ( + + + chevronLeft icon + + + + chevronLeft icon + + + + )} +
+
{prevPath && ( @@ -80,6 +105,31 @@ class IndexPage extends React.Component { )}
+ +
+ {lastPath && ( + + + chevronRight icon + + + + chevronRight icon + + + + )} +
diff --git a/utils/paginate.js b/utils/paginate.js index 1b24af8..6871fb4 100644 --- a/utils/paginate.js +++ b/utils/paginate.js @@ -39,8 +39,12 @@ module.exports = ( totalPages: pageCount, // The path to the previous paginated page (or an empty string) prevPath: paginationPath(basePath, index - 1, pageCount), + // The path to the first paginated page (or an empty string) + firstPath: paginationPath(basePath, 0, pageCount), // The path to the next paginated page (or an empty string) nextPath: paginationPath(basePath, index + 1, pageCount), + // The path to the last paginated page (or an empty string) + lastPath: paginationPath(basePath, pageCount - 1, pageCount), // Current page ID for displaying between chevrons pageID: index + 1 } diff --git a/utils/paginate.test.js b/utils/paginate.test.js index 9bfa6ef..2b76056 100644 --- a/utils/paginate.test.js +++ b/utils/paginate.test.js @@ -15,8 +15,10 @@ test('stops generating a next page link on the final paginated page', () => { ); assert.equal(createdPages.length, 16); + assert.equal(createdPages[0].context.firstPath, '/'); assert.equal(createdPages[0].context.nextPath, '/page/2'); assert.equal(createdPages[14].context.nextPath, '/page/16'); assert.equal(createdPages[15].context.pageID, 16); + assert.equal(createdPages[15].context.lastPath, '/page/16'); assert.equal(createdPages[15].context.nextPath, ''); });