|
@@ -69,72 +69,74 @@
|
|
|
{{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.instantsearch.url $js.instantsearch.version) $js.instantsearch.sri | safeHTML }}
|
|
|
{{ end }}
|
|
|
<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';
|
|
|
+ if ( $('#search-box').length ) {
|
|
|
+ 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 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')
|
|
|
+
|
|
|
+ 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
|
|
|
},
|
|
|
- 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]);
|
|
|
+ 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();
|
|
|
+ // Start search.
|
|
|
+ search.start();
|
|
|
+ }
|
|
|
</script>
|
|
|
{{ end }}
|
|
|
|