Skip to content

Commit

Permalink
fix: link text not indexing (#1609)
Browse files Browse the repository at this point in the history
* fix: link text not indexing

* fix: missing optional chaining
  • Loading branch information
dmitrymatio authored Aug 7, 2024
1 parent 4e42843 commit ec5969d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/gatsby-theme-aio/algolia/helpers/parse-mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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,
};

Expand Down

0 comments on commit ec5969d

Please sign in to comment.