I am trying to create a second blog template on my Gatsby site. I am only starting to learn Javascript so I need help with the gatsby-node.js file.
I tried to duplicate each lines of functions to create a second blog template essentially, but failed each time so if someone can walk through my code and provide the correct functions it would be very helpful.
I currently have an "articles" template which works successfully. I want to create a second "projects" template.
This is my current gatsby-node.js file that calls the "articles" blog template only.
const path = require('path');
const { createFilePath } = require('gatsby-source-filesystem');
// Look at every node when it is created
exports.onCreateNode = ({node, getNode, actions}) => {
// Check for markdown nodes
const { createNodeField } = actions;
if(node.internal.type === 'MarkdownRemark') {
// Create a slug out of the markdown filepath name
const slug = createFilePath({
node,
getNode,
basePath: 'articles'
});
// Add the newly created slug to the node itself
createNodeField({
node,
name: 'slug',
value: `/article${slug}`
});
}
};
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
graphql(`
{
allMarkdownRemark {
edges {
node {
fields {
slug
}
}
}
}
}
`).then(result => {
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/article.js`),
context: {
// Data passed to context is available in page queries as GraphQL variables.
slug: node.fields.slug,
},
})
})
resolve()
})
})
};
How can I configure this file to call for a second blog template ("projects")?