Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): fix filter by heading depth (#16344)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorblades authored and DSchau committed Aug 6, 2019
1 parent f9d51bb commit 234863c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions packages/gatsby-plugin-mdx/gatsby/source-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -71,12 +71,7 @@ module.exports = (
}
enum HeadingsMdx {
h1,
h2,
h3,
h4,
h5,
h6
${headingsMdx}
}
type MdxWordCount {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 234863c

Please sign in to comment.