Skip to content
4 changes: 1 addition & 3 deletions src/plugins/search/search.js
Original file line number Diff line number Diff 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;
Copy link
Contributor Author

@wangliang181230 wangliang181230 Dec 6, 2022

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

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

Copy link
Contributor Author

@wangliang181230 wangliang181230 Dec 14, 2022

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 || ''.

Copy link
Contributor Author

@wangliang181230 wangliang181230 Dec 14, 2022

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
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