|
1 |
| -<!-- Including InstantSearch.js library and styling --> |
2 |
| -<script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.js" ></script> |
3 |
| -<link rel=" stylesheet" href=" https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.css" > |
4 |
| -<link rel=" stylesheet" href=" https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch-theme-algolia.min.css" > |
5 |
| - |
6 |
| -<script> |
7 |
| -// Instanciating InstantSearch.js with Algolia credentials |
8 |
| -const search = instantsearch({ |
9 |
| - appId: '{{ site.algolia.application_id }}', |
10 |
| - apiKey: '{{ site.algolia.search_only_api_key }}', |
11 |
| - indexName: '{{ site.algolia.index_name }}', |
12 |
| - searchParameters: { |
13 |
| - restrictSearchableAttributes: [ |
14 |
| - 'title', |
15 |
| - 'content' |
16 |
| - ] |
17 |
| - } |
18 |
| -}); |
19 |
| - |
20 |
| -const hitTemplate = function(hit) { |
21 |
| - const url = hit.url; |
22 |
| - const title = hit._highlightResult.title.value; |
23 |
| - const content = hit._highlightResult.html.value; |
24 |
| - |
25 |
| - return ` |
26 |
| - <div class="list__item"> |
27 |
| - <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork"> |
28 |
| - <h2 class="archive__item-title" itemprop="headline"><a href="{{ site.baseurl }}${url}">${title}</a></h2> |
29 |
| - <div class="archive__item-excerpt" itemprop="description">${content}</div> |
30 |
| - </article> |
31 |
| - </div> |
32 |
| - `; |
33 |
| -} |
34 |
| - |
35 |
| -// Adding searchbar and results widgets |
36 |
| -search.addWidget( |
37 |
| - instantsearch.widgets.searchBox({ |
38 |
| - container: '.search-searchbar', |
39 |
| - placeholder: 'Enter your search term...' |
40 |
| - }) |
41 |
| -); |
42 |
| -search.addWidget( |
43 |
| - instantsearch.widgets.hits({ |
44 |
| - container: '.search-hits', |
45 |
| - templates: { |
46 |
| - item: hitTemplate |
47 |
| - } |
48 |
| - }) |
49 |
| -); |
50 |
| - |
51 |
| -// Starting the search |
52 |
| -search.start(); |
| 1 | +{% comment %}TODO consider https://developers.google.com/custom-search/docs/element{% endcomment %} |
| 2 | +{% capture google_search_site %}{{ site.url }}{{ site.baseurl }}/{% endcapture %} |
| 3 | +<script language="Javascript" type="text/javascript"> |
| 4 | + function google_search() { |
| 5 | + var query = document.getElementById("google-search").value; |
| 6 | + window.open("https://www.google.com/search?q=" + query + "+site:" + "{{ google_search_site | cgi_escape }}"); |
| 7 | + } |
53 | 8 | </script>
|
| 9 | + |
| 10 | +<form id="search" onsubmit="google_search(); return false;"> |
| 11 | + <input type="text" id="google-search" placeholder="{{ site.data.language.enter_search_term }}"> |
| 12 | +</form> |
| 13 | +<noscript> |
| 14 | + Search <a href="https://www.google.com/search?q=site:{{ google_search_site | cgi_escape }}" target="_blank">Google</a> for: |
| 15 | + <pre><code>search-term site:{{ google_search_site }}</code></pre> |
| 16 | +</noscript> |
0 commit comments