From 234863c66cef860b61c1a07e9a0edaf0455f4159 Mon Sep 17 00:00:00 2001 From: Trevor Blades Date: Tue, 6 Aug 2019 14:25:43 -0400 Subject: [PATCH] fix(gatsby-plugin-mdx): fix filter by heading depth (#16344) --- packages/gatsby-plugin-mdx/gatsby/source-nodes.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js b/packages/gatsby-plugin-mdx/gatsby/source-nodes.js index 40e55c8f9aedf..892eed2b807eb 100644 --- a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js +++ b/packages/gatsby-plugin-mdx/gatsby/source-nodes.js @@ -59,7 +59,7 @@ module.exports = ( const { createTypes } = actions; const options = defaultOptions(pluginOptions); - + const headingsMdx = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; createTypes(` type MdxFrontmatter { title: String! @@ -71,12 +71,7 @@ module.exports = ( } enum HeadingsMdx { - h1, - h2, - h3, - h4, - h5, - h6 + ${headingsMdx} } type MdxWordCount { @@ -172,8 +167,8 @@ module.exports = ( depth: heading.depth }); }); - if (typeof depth === `number`) { - headings = headings.filter(heading => heading.depth === depth); + if (headingsMdx.includes(depth)) { + headings = headings.filter(heading => `h${heading.depth}` === depth); } return headings; }