From ec5969d8e6594d2555ded8e0f9c92530b84c88c2 Mon Sep 17 00:00:00 2001 From: Dmitry Matiouchenko Date: Wed, 7 Aug 2024 16:38:20 -0700 Subject: [PATCH] fix: link text not indexing (#1609) * fix: link text not indexing * fix: missing optional chaining --- .../algolia/helpers/parse-mdx.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-theme-aio/algolia/helpers/parse-mdx.js b/packages/gatsby-theme-aio/algolia/helpers/parse-mdx.js index dc0821f709..808ee170a7 100644 --- a/packages/gatsby-theme-aio/algolia/helpers/parse-mdx.js +++ b/packages/gatsby-theme-aio/algolia/helpers/parse-mdx.js @@ -11,7 +11,6 @@ */ const { selectAll } = require('unist-util-select'); -const uuid = require('uuid'); function parseMdx(markdownFile) { // See: https://github.com/syntax-tree/mdast for node type info. @@ -30,7 +29,14 @@ function parseMdx(markdownFile) { nodeValue = mdastNode.type === 'code' ? mdastNode.value - : mdastNode.children.map(child => child.value).join(''); + : mdastNode.children + .map(child => { + if (child.type === 'link') { + return child?.children?.find(child => child.type === 'text')?.value; + } + return child?.value; + }) + .join(''); if (nodeValue.length < minCharLength) continue; @@ -42,9 +48,14 @@ function parseMdx(markdownFile) { anchor: getAnchor(mdastNode, markdownFile), featured: markdownFile.featured, category: markdownFile.category, - title: markdownFile.title === '' || markdownFile.title == null ? markdownFile.headings[0]?.value : markdownFile.title, + title: + markdownFile.title === '' || markdownFile.title == null + ? markdownFile.headings[0]?.value + : markdownFile.title, description: - markdownFile.description === '' || markdownFile.description == null ? markdownFile.excerpt : markdownFile.description, + markdownFile.description === '' || markdownFile.description == null + ? markdownFile.excerpt + : markdownFile.description, words: nodeValue.split(' ').length, };