|
1 | | -<div id="search-bar" class="h-full relative flex items-center overflow-visible"> |
| 1 | +<div id="search-bar" class="h-full relative flex items-center overflow-visible" x-data="{ isSafari: /^((?!chrome|android).)*safari/i.test(navigator.userAgent) }"> |
2 | 2 | <button |
3 | 3 | type="button" |
4 | 4 | aria-label="Search" |
5 | 5 | class="cursor-pointer flex items-center gap-2 p-2 rounded-lg bg-blue-700 border border-blue-500 text-white transition-colors focus:outline-none focus:ring focus:ring-blue-400 hover:bg-blue-800 hover:border-blue-400" |
6 | 6 | id="search-modal-trigger" |
| 7 | + x-show="!isSafari" |
7 | 8 | > |
8 | 9 | <span class="icon-svg"> |
9 | 10 | {{ partialCached "icon" "search" "search" }} |
|
43 | 44 | Start typing to search the documentation |
44 | 45 | </p> |
45 | 46 | <pagefind-summary></pagefind-summary> |
46 | | - <pagefind-results></pagefind-results> |
| 47 | + <pagefind-results> |
| 48 | + <script type="text/pagefind-template"> |
| 49 | + <li class="py-3 border-b border-gray-200 dark:border-gray-700 last:border-b-0"> |
| 50 | + {{ print "{{#if meta.breadcrumbs}}" }} |
| 51 | + <p class="text-xs text-gray-500 dark:text-gray-400 mb-1">{{ print "{{ meta.breadcrumbs }}" }}</p> |
| 52 | + {{ print "{{/if}}" }} |
| 53 | + <p class="font-medium"> |
| 54 | + <a class="text-blue-600 dark:text-blue-400 hover:underline" href="{{ print "{{ meta.url | default(url) | safeUrl }}" }}"> |
| 55 | + {{ print "{{ meta.title }}" }} |
| 56 | + </a> |
| 57 | + </p> |
| 58 | + {{ print "{{#if excerpt}}" }} |
| 59 | + <p class="text-gray-600 dark:text-gray-400 mt-1 text-sm">{{ print "{{+ excerpt +}}" }}</p> |
| 60 | + {{ print "{{/if}}" }} |
| 61 | + {{ print "{{#if sub_results}}" }} |
| 62 | + <ul class="mt-3 ml-4 flex flex-wrap gap-2"> |
| 63 | + {{ print "{{#each sub_results as sub}}" }} |
| 64 | + {{ print "{{#if (lt @index 5)}}" }} |
| 65 | + <li class="text-sm"> |
| 66 | + <a class="text-blue-600 dark:text-blue-400 hover:underline" href="{{ print "{{ sub.url | safeUrl }}" }}"> |
| 67 | + {{ print "{{ sub.title }}" }} |
| 68 | + </a> |
| 69 | + </li> |
| 70 | + {{ print "{{/if}}" }} |
| 71 | + {{ print "{{/each}}" }} |
| 72 | + </ul> |
| 73 | + {{ print "{{/if}}" }} |
| 74 | + </li> |
| 75 | + </script> |
| 76 | + </pagefind-results> |
47 | 77 | </pagefind-modal-body> |
48 | 78 | </pagefind-modal> |
49 | 79 | `); |
50 | 80 |
|
51 | 81 | const modal = document.getElementById('search-modal'); |
52 | 82 | const placeholder = document.getElementById('search-placeholder'); |
53 | 83 |
|
54 | | - // Custom result template |
55 | | - modal.querySelector('pagefind-results').resultTemplate = (result) => { |
56 | | - const li = document.createElement('li'); |
57 | | - li.className = 'py-3 border-b border-gray-200 dark:border-gray-700 last:border-b-0'; |
58 | | - |
59 | | - const title = document.createElement('p'); |
60 | | - title.className = 'font-medium'; |
61 | | - |
62 | | - const link = document.createElement('a'); |
63 | | - link.className = 'text-blue-600 dark:text-blue-400 hover:underline'; |
64 | | - link.href = result.meta.url || result.url; |
65 | | - link.textContent = result.meta.title; |
66 | | - title.appendChild(link); |
67 | | - li.appendChild(title); |
68 | | - |
69 | | - if (result.excerpt) { |
70 | | - const excerpt = document.createElement('p'); |
71 | | - excerpt.className = 'text-gray-600 dark:text-gray-400 mt-1 text-sm'; |
72 | | - excerpt.innerHTML = result.excerpt; |
73 | | - li.appendChild(excerpt); |
74 | | - } |
75 | | - |
76 | | - if (result.sub_results?.length) { |
77 | | - const ul = document.createElement('ul'); |
78 | | - ul.className = 'mt-3 ml-4 flex flex-wrap gap-2'; |
79 | | - for (const sub of result.sub_results) { |
80 | | - const subLi = document.createElement('li'); |
81 | | - subLi.className = 'text-sm'; |
82 | | - const subLink = document.createElement('a'); |
83 | | - subLink.className = 'text-blue-600 dark:text-blue-400 hover:underline'; |
84 | | - subLink.href = sub.url; |
85 | | - subLink.textContent = sub.title; |
86 | | - subLi.appendChild(subLink); |
87 | | - ul.appendChild(subLi); |
88 | | - } |
89 | | - li.appendChild(ul); |
90 | | - } |
91 | | - |
92 | | - return li; |
93 | | - }; |
94 | | - |
95 | 84 | // Show/hide placeholder based on search state |
96 | 85 | const instance = getInstanceManager().getInstance('default'); |
97 | 86 | instance.on('search', (term) => { |
|
0 commit comments