diff --git a/config/search.js b/config/search.js index 193fd35..f9f9003 100644 --- a/config/search.js +++ b/config/search.js @@ -16,19 +16,40 @@ const searchPluginConfig = { fields { path } + tableOfContents } } } `, index: ["title"], normalizer: ({ data }) => - data.allMdx.nodes.map((node) => ({ - id: node.id, - title: node.frontmatter.title, - description: node.frontmatter.description, - url: node.fields.path, - isExternal: false, - })), + data.allMdx.nodes.flatMap((node) => { + // return at least the main page ("node") + const returnVal = [ + { + id: node.id, + title: node.frontmatter.title, + description: node.frontmatter.description, + url: node.fields.path, + isExternal: false, + toc: node.tableOfContents, + }, + ]; + + // add the headers too if they're in ToC + if (node.tableOfContents.items != null) { + node.tableOfContents.items.map((header) => + returnVal.push({ + id: node.id.concat(header.url), + title: node.frontmatter.title.concat(" - ", header.title), + url: node.fields.path.concat(header.url), + isExternal: false, + }) + ); + } + + return returnVal; + }), }, };