{"data":{"markdownRemark":{"html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const _ = require(&quot;lodash&quot;)\n\nexports.onCreateNode = ({ node, boundActionCreators, getNode }) =&gt; {\n     const { createNodeField } = boundActionCreators;\n   \n     if (_.get(node, &quot;internal.type&quot;) === `MarkdownRemark`) {\n       // Get the parent node\n       const parent = getNode(_.get(node, &quot;parent&quot;));\n   \n       // Create a field on this node for the &quot;collection&quot; of the parent\n       // NOTE: This is necessary so we can filter `allMarkdownRemark` by\n       // `collection` otherwise there is no way to filter for only markdown\n       // documents of type `post`.\n       createNodeField({\n         node,\n         name: &quot;collection&quot;,\n         value: _.get(parent, &quot;sourceInstanceName&quot;)\n       });\n     }\n   };</code></pre></div>","excerpt":"","timeToRead":1,"frontmatter":{"date":"May 29, 2018","path":"/add-type-field-for-markdown-sources","title":"Add type field for markdown sources"}},"relatedPosts":{"edges":[{"node":{"id":"d6d93bab-2419-57f5-8255-e2a4d005fb3a","frontmatter":{"title":"Render pages from markdown sources","path":"/render-pages-from-markdown-sources","tags":["v1"]}}},{"node":{"id":"d2b7cd1f-bda7-5da1-8d51-23a38a68c0d4","frontmatter":{"title":"Pagination Plugin for GatsbyJS","path":"/gatsby-awesome-pagination","tags":["v1"]}}}]},"allCommentsJson":null,"allRatingsJson":null},"pageContext":{"tags":["v1"]}}