|
1 | 1 | const instantsearch = require('instantsearch.js').default |
2 | | -const { searchBox, hits } = require('instantsearch.js/es/widgets') |
| 2 | +const { searchBox, hits, configure } = require('instantsearch.js/es/widgets') |
3 | 3 | const algoliasearch = require('algoliasearch') |
4 | 4 | const searchWithYourKeyboard = require('search-with-your-keyboard') |
5 | 5 | const querystring = require('querystring') |
@@ -131,34 +131,39 @@ export default function () { |
131 | 131 |
|
132 | 132 | const search = instantsearch(opts) |
133 | 133 |
|
134 | | - search.addWidget( |
135 | | - hits({ |
136 | | - container: '#search-results-container', |
137 | | - templates: { |
138 | | - empty: 'No results', |
139 | | - item: resultTemplate |
140 | | - }, |
141 | | - // useful for debugging template context, if needed |
142 | | - transformItems: items => { |
143 | | - // console.log(`transformItems`, items) |
144 | | - return items |
145 | | - } |
146 | | - }) |
147 | | - ) |
148 | | - |
149 | 134 | // Find search placeholder text in a <meta> tag, falling back to a default |
150 | 135 | const placeholderMeta = document.querySelector('meta[name="site.data.ui.search.placeholder"]') |
151 | 136 | const placeholder = placeholderMeta ? placeholderMeta.content : 'Search topics, products...' |
152 | 137 |
|
153 | | - search.addWidget( |
154 | | - searchBox({ |
155 | | - container: '#search-input-container', |
156 | | - placeholder, |
157 | | - // only autofocus on the homepage, and only if no #hash is present in the URL |
158 | | - autofocus: (hasStandaloneSearch()) && !window.location.hash.length, |
159 | | - showReset: false, |
160 | | - showSubmit: false |
161 | | - }) |
| 138 | + search.addWidgets( |
| 139 | + [ |
| 140 | + hits({ |
| 141 | + container: '#search-results-container', |
| 142 | + templates: { |
| 143 | + empty: 'No results', |
| 144 | + item: resultTemplate |
| 145 | + }, |
| 146 | + // useful for debugging template context, if needed |
| 147 | + transformItems: items => { |
| 148 | + // console.log(`transformItems`, items) |
| 149 | + return items |
| 150 | + } |
| 151 | + }), |
| 152 | + configure({ |
| 153 | + analyticsTags: [ |
| 154 | + 'site:docs.github.com', |
| 155 | + `env:${process.env.NODE_ENV}` |
| 156 | + ] |
| 157 | + }), |
| 158 | + searchBox({ |
| 159 | + container: '#search-input-container', |
| 160 | + placeholder, |
| 161 | + // only autofocus on the homepage, and only if no #hash is present in the URL |
| 162 | + autofocus: (hasStandaloneSearch()) && !window.location.hash.length, |
| 163 | + showReset: false, |
| 164 | + showSubmit: false |
| 165 | + }) |
| 166 | + ] |
162 | 167 | ) |
163 | 168 |
|
164 | 169 | // enable for debugging |
|
0 commit comments