2018-11-09 18:08:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
const { createFilePath } = require('gatsby-source-filesystem');
|
|
|
|
|
|
|
|
const onCreateNode = ({ node, actions, getNode }) => {
|
|
|
|
const { createNodeField } = actions;
|
|
|
|
|
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
2018-11-12 18:38:36 +01:00
|
|
|
if (typeof node.frontmatter.slug !== 'undefined') {
|
2019-12-12 05:27:28 +01:00
|
|
|
const dirname = getNode(node.parent).relativeDirectory;
|
2018-11-09 18:08:48 +01:00
|
|
|
createNodeField({
|
|
|
|
node,
|
|
|
|
name: 'slug',
|
2019-12-12 05:27:28 +01:00
|
|
|
value: `/${dirname}/${node.frontmatter.slug}`
|
2018-11-09 18:08:48 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const value = createFilePath({ node, getNode });
|
|
|
|
createNodeField({
|
|
|
|
node,
|
2018-11-12 22:28:02 +01:00
|
|
|
name: 'slug',
|
|
|
|
value
|
2018-11-09 18:08:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.frontmatter.tags) {
|
2018-11-11 12:19:06 +01:00
|
|
|
const tagSlugs = node.frontmatter.tags.map((tag) => `/tag/${_.kebabCase(tag)}/`);
|
2018-11-09 18:08:48 +01:00
|
|
|
createNodeField({ node, name: 'tagSlugs', value: tagSlugs });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.frontmatter.category) {
|
2018-11-11 12:19:06 +01:00
|
|
|
const categorySlug = `/category/${_.kebabCase(node.frontmatter.category)}/`;
|
2018-11-09 18:08:48 +01:00
|
|
|
createNodeField({ node, name: 'categorySlug', value: categorySlug });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = onCreateNode;
|