title: Gatsby: Multiple Content Types
body: <p>Im trying to get up to speed on Gatsby and have great success with the demos, but am running into a wall with what I feel like is a relatively common and simple use case. I would like to have multiple content types that I can write in Markdown, each that has different Frontmatter, and each that has a different template.</p>
  
  <p>For example, I would like a BlogPost content type and and a Project content type:</p>
  
  <h1>BlogPost Content Type</h1>
  
  <pre><code>---
  title: My Post
  date: "2017-09-21"
  ---
  
  This is my blog body
  </code></pre>
  
  <h1>Project Content Type</h1>
  
  <pre><code>---
  projectName: My Project
  startDate: "2017-09-21"
  endDate: "2017-10-21"
  ---
  
  This is my project description
  </code></pre>
  
  <p>And then to have them render in the relevant Template, I had to do some hacky stuff in <code>gatsby-node.js</code> using regular expressions:</p>
  
  <pre><code>const components = {
    blog: `./src/templates/blog-post.js`,
    projects: `./src/templates/project-post.js`,
  }
  exports.createPages = ({ graphql, boundActionCreators }) =&gt; {
    const { createPage } = boundActionCreators
    RE_DIR = new RegExp("\/pages\/([a-z]+)\/.*\.md$");
    return new Promise((resolve, reject) =&gt; {
      graphql(`
        {
          allMarkdownRemark {
            edges {
              node {
                fileAbsolutePath
                fields {
                  slug
                }
              }
            }
          }
        }
      `).then(result =&gt; {
        result.data.allMarkdownRemark.edges.forEach(({ node }) =&gt; {
          // console.log(RE_DIR.exec(node.fileAbsolutePath))
  
  
          const postType = RE_DIR.exec(node.fileAbsolutePath)[1]
  
          if (postType) {
            createPage({
              path: node.fields.slug,
              component: path.resolve(components[postType]),
              context: {
                // Data passed to context is available in page queries as GraphQL variables.
                slug: node.fields.slug,
              },
            })
          }
  
  
        })
        resolve()
      })
    })
  };
  </code></pre>
  
  <p>The problem Im having now, is since the frontmatter is inconsistent, it appears GraphQL only picks up the frontmatter schema from one of the sources.  </p>
  
  <p>Is there an easier way to have multiple content types?</p>