mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-29 13:42:28 +02:00
Upgrade to Gatsby v2
This commit is contained in:
30
gatsby/pagination/create-posts-pages.js
Normal file
30
gatsby/pagination/create-posts-pages.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const siteConfig = require('../../config.js');
|
||||
|
||||
module.exports = async (graphql, actions) => {
|
||||
const { createPage } = actions;
|
||||
|
||||
const result = await graphql(`
|
||||
{
|
||||
allMarkdownRemark(
|
||||
filter: { frontmatter: { layout: { eq: "post" }, draft: { ne: true } } }
|
||||
) { totalCount }
|
||||
}
|
||||
`);
|
||||
|
||||
const numPages = Math.ceil(result.data.allMarkdownRemark.totalCount / siteConfig.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,
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user