mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2024-12-25 22:39:41 +01:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const { createFilePath } = require('gatsby-source-filesystem');
|
|
const { fmImagesToRelative } = require('gatsby-remark-relative-images');
|
|
|
|
const onCreateNode = ({ node, actions, getNode }) => {
|
|
const { createNodeField } = actions;
|
|
|
|
fmImagesToRelative(node);
|
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
|
if (typeof node.frontmatter.slug !== 'undefined') {
|
|
createNodeField({
|
|
node,
|
|
name: 'slug',
|
|
value: node.frontmatter.slug
|
|
});
|
|
} else {
|
|
const value = createFilePath({ node, getNode });
|
|
createNodeField({
|
|
node,
|
|
name: 'slug',
|
|
value
|
|
});
|
|
}
|
|
|
|
if (node.frontmatter.tags) {
|
|
const tagSlugs = node.frontmatter.tags.map((tag) => `/tag/${_.kebabCase(tag)}/`);
|
|
createNodeField({ node, name: 'tagSlugs', value: tagSlugs });
|
|
}
|
|
|
|
if (node.frontmatter.category) {
|
|
const categorySlug = `/category/${_.kebabCase(node.frontmatter.category)}/`;
|
|
createNodeField({ node, name: 'categorySlug', value: categorySlug });
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = onCreateNode;
|