(result: SearchResult, index: number, query: string)
| 303 | } |
| 304 | |
| 305 | function createSearchResult(result: SearchResult, index: number, query: string) { |
| 306 | const { item } = result; |
| 307 | const link = document.createElement("a"); |
| 308 | link.className = `search-result search-result-${item.type}`; |
| 309 | link.href = item.href; |
| 310 | link.id = `search-result-${index}`; |
| 311 | link.setAttribute("role", "option"); |
| 312 | link.setAttribute("aria-selected", index === activeSearchIndex ? "true" : "false"); |
| 313 | link.dataset.searchIndex = String(index); |
| 314 | if (index === activeSearchIndex) link.classList.add("is-active"); |
| 315 | |
| 316 | const icon = document.createElement("span"); |
| 317 | icon.className = "search-result-icon"; |
| 318 | const logo = document.createElement("img"); |
| 319 | logo.src = item.logo; |
| 320 | logo.alt = ""; |
| 321 | logo.loading = "lazy"; |
| 322 | icon.append(logo); |
| 323 | link.append(icon); |
| 324 | |
| 325 | const body = document.createElement("span"); |
| 326 | body.className = "search-result-body"; |
| 327 | |
| 328 | const top = document.createElement("span"); |
| 329 | top.className = "search-result-top"; |
| 330 | |
| 331 | const title = document.createElement("span"); |
| 332 | title.className = "search-result-title"; |
| 333 | appendHighlightedText(title, item.title, query); |
| 334 | top.append(title); |
| 335 | |
| 336 | const kind = document.createElement("span"); |
| 337 | kind.className = "search-result-kind"; |
| 338 | kind.textContent = item.type; |
| 339 | top.append(kind); |
| 340 | body.append(top); |
| 341 | |
| 342 | const subtitle = document.createElement("span"); |
| 343 | subtitle.className = "search-result-subtitle mono"; |
| 344 | appendHighlightedText(subtitle, resultSubtitle(item), query); |
| 345 | body.append(subtitle); |
| 346 | |
| 347 | const meta = document.createElement("span"); |
| 348 | meta.className = "search-result-meta"; |
| 349 | for (const value of resultMeta(item)) { |
| 350 | const chip = document.createElement("span"); |
| 351 | chip.textContent = value; |
| 352 | meta.append(chip); |
| 353 | } |
| 354 | body.append(meta); |
| 355 | |
| 356 | link.append(body); |
| 357 | return link; |
| 358 | } |
| 359 | |
| 360 | function updateActiveSearchResult() { |
| 361 | if (!searchResults || !searchInput) return; |
no test coverage detected