mirror of
				https://github.com/mastermindzh/rickvanlieshout.com
				synced 2025-11-03 18:19:39 +01:00 
			
		
		
		
	Posts no longer need to specify a full url for the resulting html. Rather, the prefix portion of the url will be inferred from the post's location in the source filesystem. The post slug now simply represents a url friendly version of the title. Additionally, updates all sample posts to use the new slug format.
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'use strict';
 | 
						|
 | 
						|
const _ = require('lodash');
 | 
						|
const { createFilePath } = require('gatsby-source-filesystem');
 | 
						|
 | 
						|
const onCreateNode = ({ node, actions, getNode }) => {
 | 
						|
  const { createNodeField } = actions;
 | 
						|
 | 
						|
  if (node.internal.type === 'MarkdownRemark') {
 | 
						|
    if (typeof node.frontmatter.slug !== 'undefined') {
 | 
						|
      const dirname = getNode(node.parent).relativeDirectory;
 | 
						|
      createNodeField({
 | 
						|
        node,
 | 
						|
        name: 'slug',
 | 
						|
        value: `/${dirname}/${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;
 |