Skip to content

Commit 4bad018

Browse files
authored
Merge pull request #24109 from dvdksn/fix-search-results-safari
fix search results safari
2 parents cf935f3 + 734cf9c commit 4bad018

2 files changed

Lines changed: 33 additions & 44 deletions

File tree

layouts/partials/pagefind-meta.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{- $description := partial "utils/description.html" . -}}
33
{{- $keywords := partialCached "utils/keywords.html" . . -}}
44
{{- $breadcrumbs := slice -}}
5-
{{- range .Ancestors.Reverse -}}
5+
{{- range after 1 .Ancestors.Reverse -}}
66
{{- $breadcrumbs = $breadcrumbs | append .LinkTitle -}}
77
{{- end -}}
88
{{- with $description }}<meta data-pagefind-meta="description:{{ . }}">{{ end }}

layouts/partials/search-bar.html

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
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) }">
22
<button
33
type="button"
44
aria-label="Search"
55
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"
66
id="search-modal-trigger"
7+
x-show="!isSafari"
78
>
89
<span class="icon-svg">
910
{{ partialCached "icon" "search" "search" }}
@@ -43,55 +44,43 @@
4344
Start typing to search the documentation
4445
</p>
4546
<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>
4777
</pagefind-modal-body>
4878
</pagefind-modal>
4979
`);
5080

5181
const modal = document.getElementById('search-modal');
5282
const placeholder = document.getElementById('search-placeholder');
5383

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-
9584
// Show/hide placeholder based on search state
9685
const instance = getInstanceManager().getInstance('default');
9786
instance.on('search', (term) => {

0 commit comments

Comments
 (0)