|
133 | 133 | document.head.appendChild(link); |
134 | 134 | } |
135 | 135 |
|
136 | | - function highlightPageTitle (title, terms) { |
137 | | - const positions = getTermPosition(title, terms); |
138 | | - return buildHighlightedText(title, positions, snippetLength) |
139 | | - } |
140 | | - |
141 | 136 | function highlightSectionTitle (sectionTitle, terms) { |
142 | 137 | if (sectionTitle) { |
143 | | - const text = sectionTitle.text; |
| 138 | + const text = sectionTitle.title ?? sectionTitle.text; |
144 | 139 | const positions = getTermPosition(text, terms); |
145 | 140 | return buildHighlightedText(text, positions, snippetLength) |
146 | 141 | } |
|
156 | 151 | return [] |
157 | 152 | } |
158 | 153 |
|
159 | | - function highlightText (doc, terms) { |
160 | | - const text = doc.text; |
| 154 | + function highlightText (text, terms) { |
161 | 155 | const positions = getTermPosition(text, terms); |
162 | 156 | return buildHighlightedText(text, positions, snippetLength) |
163 | 157 | } |
|
183 | 177 | } |
184 | 178 | } |
185 | 179 | return { |
186 | | - pageTitleNodes: highlightPageTitle(doc.title, terms.title || []), |
| 180 | + pageTitleNodes: highlightText(doc.title, terms.title || []), |
187 | 181 | sectionTitleNodes: highlightSectionTitle(sectionTitle, terms.title || []), |
188 | | - pageContentNodes: highlightText(doc, terms.text || []), |
| 182 | + pageContentNodes: highlightText( |
| 183 | + sectionTitle?.title && sectionTitle.text ? sectionTitle.text : doc.text, |
| 184 | + terms.text || [] |
| 185 | + ), |
189 | 186 | pageKeywordNodes: highlightKeyword(doc, terms.keyword || []), |
190 | 187 | } |
191 | 188 | } |
|
199 | 196 | let sectionTitle; |
200 | 197 | if (ids.length > 1) { |
201 | 198 | const titleId = ids[1]; |
202 | | - sectionTitle = doc.titles.filter(function (item) { |
| 199 | + sectionTitle = doc.titles.find(function (item) { |
203 | 200 | return String(item.id) === titleId |
204 | | - })[0]; |
| 201 | + }); |
205 | 202 | } |
206 | 203 | const metadata = item.matchData.metadata; |
207 | | - const highlightingResult = highlightHit(metadata, sectionTitle, doc); |
| 204 | + const highlightingResult = highlightHit(metadata, sectionTitle || doc, doc); |
208 | 205 | const componentVersion = store.componentVersions[`${doc.component}/${doc.version}`]; |
209 | 206 | if (componentVersion !== undefined && currentComponent !== componentVersion) { |
210 | 207 | const searchResultComponentHeader = document.createElement('div'); |
|
0 commit comments