|
11 | 11 | {{ partial "overview_block.html" .}} |
12 | 12 |
|
13 | 13 | <style> |
14 | | -.algolia-search { |
15 | | - .search-panel { |
16 | | - display: flex; |
17 | | - } |
| 14 | + .algolia-search { |
| 15 | + .search-panel { |
| 16 | + display: flex; |
| 17 | + } |
18 | 18 |
|
19 | | - .search-panel__results { |
20 | | - flex: 3; |
21 | | - } |
| 19 | + .search-panel__results { |
| 20 | + flex: 3; |
| 21 | + } |
22 | 22 |
|
23 | | - .ais-Highlight-highlighted { |
24 | | - color: inherit; |
25 | | - font-size: inherit; |
26 | | - } |
| 23 | + .ais-Highlight-highlighted { |
| 24 | + color: inherit; |
| 25 | + font-size: inherit; |
| 26 | + } |
27 | 27 |
|
28 | | - #searchbox { |
29 | | - margin-bottom: 2rem; |
30 | | - } |
| 28 | + #searchbox { |
| 29 | + margin-bottom: 2rem; |
| 30 | + } |
31 | 31 |
|
32 | | - #pagination { |
33 | | - margin: 2rem auto; |
34 | | - text-align: center; |
35 | | - } |
36 | | - .search-result-row { |
37 | | - @media (min-width: 992px) { |
38 | | - height: 220px; |
| 32 | + #pagination { |
| 33 | + margin: 2rem auto; |
| 34 | + text-align: center; |
39 | 35 | } |
40 | | - } |
41 | | - .ais-Hits-item { |
42 | | - padding: 0; |
43 | | - margin-top: 10px; |
44 | | - margin-bottom: 10px; |
45 | | - } |
46 | | - .search-result-image { |
47 | | - height: auto; |
48 | | - max-height: 175px; |
49 | | - max-width: 100%; |
50 | | - margin: auto; |
51 | | - } |
52 | | - .search-result-title { |
53 | | - margin-top: 40px; |
54 | | - } |
55 | 36 |
|
56 | | - ol.ais-Hits-list { |
57 | | - list-style: none; |
58 | | - } |
59 | | - .ais-Highlight-highlighted, .ais-Snippet-highlighted { |
60 | | - background-color: #FFFF92; |
| 37 | + .search-result-row { |
| 38 | + @media (min-width: 992px) { |
| 39 | + height: 220px; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + .ais-Hits-item { |
| 44 | + padding: 0; |
| 45 | + margin-top: 10px; |
| 46 | + margin-bottom: 10px; |
| 47 | + } |
| 48 | + |
| 49 | + .search-result-image { |
| 50 | + height: auto; |
| 51 | + max-height: 175px; |
| 52 | + max-width: 100%; |
| 53 | + margin: auto; |
| 54 | + } |
| 55 | + |
| 56 | + .search-result-title { |
| 57 | + margin-top: 40px; |
| 58 | + } |
| 59 | + |
| 60 | + ol.ais-Hits-list { |
| 61 | + list-style: none; |
| 62 | + } |
| 63 | + |
| 64 | + .ais-Highlight-highlighted, |
| 65 | + .ais-Snippet-highlighted { |
| 66 | + background-color: #FFFF92; |
| 67 | + } |
61 | 68 | } |
62 | | -} |
63 | 69 | </style> |
64 | 70 | <!-- Search --> |
65 | | - <section class="section color-blue"> |
| 71 | +<section class="section color-blue"> |
66 | 72 | <div class="container algolia-search rounded-lg bg-lightblue"> |
67 | 73 | <div class="row"> |
68 | 74 | <div class="col"> |
@@ -99,39 +105,69 @@ <h2 class="pt-5 color-blue">Search</h2> |
99 | 105 | future: { preserveSharedStateOnUnmount: true }, |
100 | 106 | }); |
101 | 107 |
|
| 108 | + let lastRenderArgs; |
| 109 | + |
| 110 | + const infiniteHits = instantsearch.connectors.connectInfiniteHits( |
| 111 | + (renderArgs, isFirstRender) => { |
| 112 | + const { items, showMore, widgetParams } = renderArgs; |
| 113 | + const { container } = widgetParams; |
| 114 | + |
| 115 | + lastRenderArgs = renderArgs; |
| 116 | + |
| 117 | + if (isFirstRender) { |
| 118 | + const sentinel = document.createElement('div'); |
| 119 | + container.appendChild(document.createElement('ul')); |
| 120 | + container.appendChild(sentinel); |
| 121 | + |
| 122 | + const observer = new IntersectionObserver(entries => { |
| 123 | + entries.forEach(entry => { |
| 124 | + if (entry.isIntersecting && !lastRenderArgs.isLastPage) { |
| 125 | + showMore(); |
| 126 | + } |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + observer.observe(sentinel); |
| 131 | + |
| 132 | + return; |
| 133 | + } |
| 134 | + |
| 135 | + container.querySelector('ul').innerHTML = items |
| 136 | + .map( |
| 137 | + item => { |
| 138 | + return ` |
| 139 | + <a href=${item.url} class="container"> |
| 140 | + <div class="row search-result-row bg-white"> |
| 141 | + <div class="col-12 col-lg-2"> |
| 142 | + <div class="my-3"> |
| 143 | + <img class="image-fluid search-result-image d-flex" src=${item.image} alt=${item.title} /> |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + <div class="col-12 col-lg-10"> |
| 147 | + <h3 class="color-blue search-result-title">${item.title}</h3> |
| 148 | + <p class="color-gray search-result-subtitle">${item.subtitle}</p> |
| 149 | + </div> |
| 150 | + </div> |
| 151 | + </a> |
| 152 | + `; |
| 153 | + }) |
| 154 | + .join(''); |
| 155 | + } |
| 156 | + ); |
102 | 157 | search.addWidgets([ |
103 | 158 | instantsearch.widgets.searchBox({ |
104 | 159 | container: '#searchbox', |
105 | 160 | }), |
106 | | - instantsearch.widgets.hits({ |
107 | | - container: '#hits', |
108 | | - templates: { |
109 | | - item: (hit, { html, components }) => html` |
110 | | - <a href=${hit.url} class="container"> |
111 | | - <div class="row search-result-row"> |
112 | | - <div class="col-12 col-lg-2"> |
113 | | - <div class="my-3"> |
114 | | - <img class="image-fluid search-result-image d-flex" src=${hit.image} alt=${hit.title} /> |
115 | | - </div> |
116 | | - </div> |
117 | | - <div class="col-12 col-lg-10"> |
118 | | - <h3 class="color-blue search-result-title">${components.Highlight({ hit, attribute: 'title' })}</h3> |
119 | | - <p class="color-gray search-result-subtitle">${components.Highlight({ hit, attribute: 'subtitle' })}</p> |
120 | | - </div> |
121 | | - </div> |
122 | | - </a> |
123 | | - `, |
124 | | - }, |
125 | | - }), |
126 | 161 | instantsearch.widgets.configure({ |
127 | 162 | hitsPerPage: 8, |
128 | 163 | filters: "language:{{$.Site.Language.Lang}}" |
129 | 164 | }), |
130 | | - instantsearch.widgets.pagination({ |
131 | | - container: '#pagination', |
| 165 | + infiniteHits({ |
| 166 | + container: document.querySelector('#hits'), |
132 | 167 | }), |
133 | 168 | ]); |
134 | 169 |
|
| 170 | + |
135 | 171 | search.start(); |
136 | 172 | </script> |
137 | 173 | <!-- /Search --> |
|
0 commit comments