Skip to content
4 changes: 1 addition & 3 deletions src/plugins/search/search.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -128,9 +128,7 @@ export function genIndex(path, content = '', router, depth) {
token.text = getTableData(token);
token.text = getListData(token);

index[slug].body = index[slug].body
? index[slug].body + token.text
: token.text;

@wangliang181230wangliang181230Dec 6, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index[slug].body is always undefined, see the line 122

120if(!index[slug]){121index[slug]={ slug,title: '',body: ''};122}elseif(index[slug].body){
......
127}else{
...... //index[slug].body is always undefined}

@wangliang181230wangliang181230Dec 14, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the token.text is undefined, it will make the index[slug].body also undefined.
So I change the token.text to token.text || ''.

@wangliang181230wangliang181230Dec 14, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code index[slug].body ? index[slug].body + token.text : is redundant, and it is not the cause of the bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice point.

index[slug].body = token.text || '';
}
}
});
Expand Down