2018-11-09 18:08:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const createCategoriesPages = require('./pagination/create-categories-pages.js');
|
|
|
|
const createTagsPages = require('./pagination/create-tags-pages.js');
|
|
|
|
const createPostsPages = require('./pagination/create-posts-pages.js');
|
|
|
|
|
|
|
|
const createPages = async ({ graphql, actions }) => {
|
|
|
|
const { createPage } = actions;
|
|
|
|
|
|
|
|
// 404
|
|
|
|
createPage({
|
|
|
|
path: '/404',
|
|
|
|
component: path.resolve('./src/templates/not-found-template.js')
|
|
|
|
});
|
|
|
|
|
|
|
|
// Tags list
|
|
|
|
createPage({
|
|
|
|
path: '/tags',
|
|
|
|
component: path.resolve('./src/templates/tags-list-template.js')
|
|
|
|
});
|
|
|
|
|
|
|
|
// Categories list
|
|
|
|
createPage({
|
|
|
|
path: '/categories',
|
|
|
|
component: path.resolve('./src/templates/categories-list-template.js')
|
|
|
|
});
|
|
|
|
|
|
|
|
// Posts and pages from markdown
|
|
|
|
const result = await graphql(`
|
|
|
|
{
|
|
|
|
allMarkdownRemark(
|
|
|
|
filter: { frontmatter: { draft: { ne: true } } }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
frontmatter {
|
2018-11-11 17:32:51 +01:00
|
|
|
template
|
2018-11-09 18:08:48 +01:00
|
|
|
}
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const { edges } = result.data.allMarkdownRemark;
|
|
|
|
|
|
|
|
_.each(edges, (edge) => {
|
2018-11-11 17:32:51 +01:00
|
|
|
if (_.get(edge, 'node.frontmatter.template') === 'page') {
|
2018-11-09 18:08:48 +01:00
|
|
|
createPage({
|
|
|
|
path: edge.node.fields.slug,
|
|
|
|
component: path.resolve('./src/templates/page-template.js'),
|
|
|
|
context: { slug: edge.node.fields.slug }
|
|
|
|
});
|
2018-11-11 17:32:51 +01:00
|
|
|
} else if (_.get(edge, 'node.frontmatter.template') === 'post') {
|
2018-11-09 18:08:48 +01:00
|
|
|
createPage({
|
|
|
|
path: edge.node.fields.slug,
|
|
|
|
component: path.resolve('./src/templates/post-template.js'),
|
|
|
|
context: { slug: edge.node.fields.slug }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Feeds
|
|
|
|
await createTagsPages(graphql, actions);
|
|
|
|
await createCategoriesPages(graphql, actions);
|
|
|
|
await createPostsPages(graphql, actions);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = createPages;
|