Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,6 +45,31 @@ class IndexPage extends React.Component {
</ul>

<div className="flex justify-center cabin b ma4">
<div className="ph2">
{firstPath && (
<Link to={firstPath}>
<svg
className="w1"
data-icon={"chevronLeft"}
viewBox={"0 0 32 32"}
style={{ fill: `currentcolor` }}
>
<title>chevronLeft icon</title>
<path d="M20 1 L24 5 L14 16 L24 27 L20 31 L6 16 z" />
</svg>
<svg
className="w1"
data-icon={"chevronLeft"}
viewBox={"0 0 32 32"}
style={{ fill: `currentcolor` }}
>
<title>chevronLeft icon</title>
<path d="M20 1 L24 5 L14 16 L24 27 L20 31 L6 16 z" />
</svg>
</Link>
)}
</div>

<div className="ph2">
{prevPath && (
<Link to={prevPath}>
Expand Down Expand Up @@ -80,6 +105,31 @@ class IndexPage extends React.Component {
</Link>
)}
</div>

<div className="ph2">
{lastPath && (
<Link to={lastPath}>
<svg
className="w1"
data-icon={"chevronRight"}
viewBox={"0 0 32 32"}
style={{ fill: `currentcolor` }}
>
<title>chevronRight icon</title>
<path d="M12 1 L26 16 L12 31 L8 27 L18 16 L8 5 z" />
</svg>
<svg
className="w1"
data-icon={"chevronRight"}
viewBox={"0 0 32 32"}
style={{ fill: `currentcolor` }}
>
<title>chevronRight icon</title>
<path d="M12 1 L26 16 L12 31 L8 27 L18 16 L8 5 z" />
</svg>
</Link>
)}
</div>
</div>
</div>
</Layout>
Expand Down
4 changes: 4 additions & 0 deletions utils/paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions utils/paginate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
});