|
@@ -78,5 +78,78 @@
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
|
|
|
+ {{/* Algolia search engine. */}}
|
|
|
+ {{ if eq .Site.Params.search.engine 1 }}
|
|
|
+ {{ printf "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/%s/instantsearch.min.js\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" $js.instantsearch.version $js.instantsearch.sri | safeHTML }}
|
|
|
+ <script>
|
|
|
+ const content_type = {
|
|
|
+ 'post': {{ i18n "posts" }},
|
|
|
+ 'project': {{ i18n "projects" }},
|
|
|
+ 'publication' : {{ i18n "publications" }},
|
|
|
+ 'talk' : {{ i18n "talks" }}
|
|
|
+ };
|
|
|
+
|
|
|
+ function getTemplate(templateName) {
|
|
|
+ return document.querySelector(`#${templateName}-template`).innerHTML;
|
|
|
+ }
|
|
|
+
|
|
|
+ const options = {
|
|
|
+ appId: {{ .Site.Params.search.algolia.app_id }},
|
|
|
+ apiKey: {{ .Site.Params.search.algolia.api_key }},
|
|
|
+ indexName: {{ .Site.Params.search.algolia.index_name }},
|
|
|
+ routing: true,
|
|
|
+ searchParameters: {
|
|
|
+ hitsPerPage: 10
|
|
|
+ },
|
|
|
+ searchFunction: function(helper) {
|
|
|
+ let searchResults = document.querySelector('#search-hits')
|
|
|
+ if (helper.state.query === '') {
|
|
|
+ searchResults.style.display = 'none';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ helper.search();
|
|
|
+ searchResults.style.display = 'block';
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const search = instantsearch(options);
|
|
|
+
|
|
|
+ // Initialize search box.
|
|
|
+ search.addWidget(
|
|
|
+ instantsearch.widgets.searchBox({
|
|
|
+ container: '#search-box',
|
|
|
+ placeholder: {{ i18n "search_placeholder" }}
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ // Initialize search results.
|
|
|
+ search.addWidget(
|
|
|
+ instantsearch.widgets.infiniteHits({
|
|
|
+ container: '#search-hits',
|
|
|
+ templates: {
|
|
|
+ empty: '<div class="search-no-results">' + {{ i18n "search_no_results" }} + '</div>',
|
|
|
+ item: getTemplate('search-hit')
|
|
|
+ },
|
|
|
+ cssClasses: {
|
|
|
+ showmoreButton: 'btn btn-primary btn-outline'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ // On render search results, localize the content type metadata.
|
|
|
+ search.on('render', function() {
|
|
|
+ $('.search-hit-type').each(function( index ) {
|
|
|
+ let content_key = $( this ).text();
|
|
|
+ if (content_key in content_type) {
|
|
|
+ $( this ).text(content_type[content_key]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // Start search.
|
|
|
+ search.start();
|
|
|
+ </script>
|
|
|
+ {{ end }}
|
|
|
+
|
|
|
</body>
|
|
|
</html>
|