Upgrade to Gatsby v2

This commit is contained in:
alxshelepenok
2018-11-09 20:08:48 +03:00
parent e83dfc6dff
commit 8b92891329
204 changed files with 18708 additions and 3904 deletions

View 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,
}
});
}
});
};

View 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,
}
});
}
};

View 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,
}
});
}
});
};