Sfoglia il codice sorgente

feat: support common queries in Algolia integration too

Intro experimental 'searchable' front matter param too
George Cushen 3 anni fa
parent
commit
36bc271272

+ 4 - 1
wowchemy/assets/js/algolia-search.js

@@ -22,11 +22,14 @@ if (typeof instantsearch === 'function' && $('#search-box').length) {
     },
     searchFunction: function (helper) {
       let searchResults = document.querySelector('#search-hits');
+      let commonQueries = document.querySelector('#search-common-queries');
       if (helper.state.query === '') {
         searchResults.style.display = 'none';
+        commonQueries.style.display = 'block';
         return;
       }
       helper.search();
+      commonQueries.style.display = 'none';
       searchResults.style.display = 'block';
     },
   };
@@ -37,7 +40,7 @@ if (typeof instantsearch === 'function' && $('#search-box').length) {
   search.addWidget(
     instantsearch.widgets.searchBox({
       container: '#search-box',
-      autofocus: false,
+      autofocus: true,
       reset: true,
       poweredBy: algoliaConfig.poweredBy,
       placeholder: i18n.placeholder,

+ 1 - 1
wowchemy/layouts/index.json

@@ -9,7 +9,7 @@
 
 {{- range $pages -}}
   {{- /* Do not index drafts or private pages. */ -}}
-  {{- if and (not .Draft) (not .Params.private) -}}
+  {{- if and (not .Draft) (not .Params.private) | and (ne .Params.searchable false) -}}
 
     {{- /* Generate page description. */ -}}
     {{- $desc := "" -}}

+ 1 - 1
wowchemy/layouts/partials/search.html

@@ -31,7 +31,7 @@
         {{ $search_queries = site.Data.search_queries }}
       {{end}}
 
-      {{ if eq $search_provider "wowchemy" | and $search_queries }}
+      {{ if $search_queries }}
       <div id="search-common-queries" class="pt-3">
         <div class="font-weight-bold pb-3">{{ i18n "search_common_queries" | default "Common searches" }}</div>
         <ul class="fa-ul">