mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-26 04:04:27 +02:00
Upgrade to Gatsby v2
This commit is contained in:
39
gatsby/pagination/create-categories-pages.js
Normal file
39
gatsby/pagination/create-categories-pages.js
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
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 } } }
|
||||
) {
|
||||
group(field: frontmatter___category) {
|
||||
fieldValue
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
_.each(result.data.allMarkdownRemark.group, (category) => {
|
||||
const numPages = Math.ceil(category.totalCount / siteConfig.postsPerPage);
|
||||
|
||||
for (let i = 0; i < numPages; i += 1) {
|
||||
createPage({
|
||||
path: i === 0 ? `/category/${_.kebabCase(category.fieldValue)}` : `/category/${_.kebabCase(category.fieldValue)}/page/${i}`,
|
||||
component: path.resolve('./src/templates/category-template.js'),
|
||||
context: {
|
||||
page: i,
|
||||
category: category.fieldValue,
|
||||
limit: siteConfig.postsPerPage,
|
||||
skip: i * siteConfig.postsPerPage,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
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,
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
39
gatsby/pagination/create-tags-pages.js
Normal file
39
gatsby/pagination/create-tags-pages.js
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
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 } } }
|
||||
) {
|
||||
group(field: frontmatter___tags) {
|
||||
fieldValue
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
_.each(result.data.allMarkdownRemark.group, (tag) => {
|
||||
const numPages = Math.ceil(tag.totalCount / siteConfig.postsPerPage);
|
||||
|
||||
for (let i = 0; i < numPages; i += 1) {
|
||||
createPage({
|
||||
path: i === 0 ? `/tag/${_.kebabCase(tag.fieldValue)}` : `/tag/${_.kebabCase(tag.fieldValue)}/page/${i}`,
|
||||
component: path.resolve('./src/templates/tag-template.js'),
|
||||
context: {
|
||||
page: i,
|
||||
tag: tag.fieldValue,
|
||||
limit: siteConfig.postsPerPage,
|
||||
skip: i * siteConfig.postsPerPage,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user