mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-29 13:42:28 +02:00
Add pagination
This commit is contained in:
@@ -14,16 +14,21 @@ module.exports = async (graphql, actions) => {
|
||||
}
|
||||
`);
|
||||
|
||||
const numPages = Math.ceil(result.data.allMarkdownRemark.totalCount / siteConfig.postsPerPage);
|
||||
const { postsPerPage } = siteConfig;
|
||||
const numPages = Math.ceil(result.data.allMarkdownRemark.totalCount / postsPerPage);
|
||||
|
||||
for (let i = 0; i < numPages; i += 1) {
|
||||
createPage({
|
||||
path: i === 0 ? '/' : `/page/${i}`,
|
||||
component: path.resolve('./src/templates/index-template.js'),
|
||||
context: {
|
||||
page: i,
|
||||
limit: siteConfig.postsPerPage,
|
||||
skip: i * siteConfig.postsPerPage,
|
||||
currentPage: i,
|
||||
postsLimit: postsPerPage,
|
||||
postsOffset: i * postsPerPage,
|
||||
prevPagePath: i <= 1 ? '/' : `/page/${i - 1}`,
|
||||
nextPagePath: `/page/${i + 1}`,
|
||||
hasPrevPage: i !== 0,
|
||||
hasNextPage: i !== numPages - 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user