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