2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

🐛 Fixed search failing for posts without excerpt

- the excerpt was `null` in some cases when post didn't have any excerpt, causing search to fail
This commit is contained in:
Rishabh 2022-07-19 11:37:20 +05:30
parent a1fab8c7f7
commit 9fc0cd7e29

View file

@ -259,7 +259,7 @@ function getMatchIndexes({text, highlight}) {
}
});
const matchRegex = new RegExp(`${highlightRegexText}`, 'ig');
let matches = text.matchAll(matchRegex);
let matches = text?.matchAll(matchRegex);
const indexes = [];
for (const match of matches) {
indexes.push({
@ -307,6 +307,8 @@ function getHighlightParts({text, highlight}) {
}
function HighlightedSection({text = '', highlight = '', isExcerpt}) {
text = text || '';
highlight = highlight || '';
let {parts, highlightIndexes} = getHighlightParts({text, highlight});
if (isExcerpt && highlightIndexes?.[0]) {
const startIdx = highlightIndexes?.[0]?.startIdx;