forked from mmistakes/minimal-mistakes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Algolia search provider (mmistakes#1531)
* Support Lunr and Algolia search providers * Document search providers and configuration * Update CHANGELOG and history close mmistakes#1416
- Loading branch information
Showing
16 changed files
with
206 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!-- Including InstantSearch.js library and styling --> | ||
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3.3/dist/instantsearch.min.js"></script> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3.3/dist/instantsearch.min.css"> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3.3/dist/instantsearch-theme-algolia.min.css"> | ||
|
||
<script> | ||
// Instanciating InstantSearch.js with Algolia credentials | ||
const search = instantsearch({ | ||
appId: '{{ site.algolia.application_id }}', | ||
apiKey: '{{ site.algolia.search_only_api_key }}', | ||
indexName: '{{ site.algolia.index_name }}', | ||
searchParameters: { | ||
restrictSearchableAttributes: [ | ||
'title', | ||
'content' | ||
] | ||
} | ||
}); | ||
|
||
const hitTemplate = function(hit) { | ||
const url = hit.url; | ||
const title = hit._highlightResult.title.value; | ||
const content = hit._highlightResult.html.value; | ||
|
||
return ` | ||
<div class="list__item"> | ||
<article class="archive__item" itemscope itemtype="http://schema.org/CreativeWork"> | ||
<h2 class="archive__item-title" itemprop="headline"><a href="{{ site.baseurl }}${url}">${title}</a></h2> | ||
<div class="archive__item-excerpt" itemprop="description">${content}</div> | ||
</article> | ||
</div> | ||
`; | ||
} | ||
|
||
// Adding searchbar and results widgets | ||
search.addWidget( | ||
instantsearch.widgets.searchBox({ | ||
container: '.search-searchbar', | ||
{% unless site.algolia.powered_by == false %}poweredBy: true,{% endunless %} | ||
placeholder: '{{ site.data.ui-text[site.locale].search_placeholder_text | default: "Enter your search term..." }}' | ||
}) | ||
); | ||
search.addWidget( | ||
instantsearch.widgets.hits({ | ||
container: '.search-hits', | ||
templates: { | ||
item: hitTemplate | ||
} | ||
}) | ||
); | ||
|
||
// Starting the search | ||
search.start(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% assign lang = site.locale | slice: 0,2 | default: "en" %} | ||
{% case lang %} | ||
{% when "gr" %} | ||
{% assign lang = "gr" %} | ||
{% else %} | ||
{% assign lang = "en" %} | ||
{% endcase %} | ||
<script src="{{ '/assets/js/lunr/lunr.min.js' | absolute_url }}"></script> | ||
<script src="{{ '/assets/js/lunr/lunr-store.js' | absolute_url }}"></script> | ||
<script src="{{ '/assets/js/lunr/lunr-' | append: lang | append: '.js' | absolute_url }}"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="search-content__inner-wrap"> | ||
{%- assign search_provider = site.search_provider | default: "lunr" -%} | ||
{%- case search_provider -%} | ||
{%- when "lunr" -%} | ||
<input type="text" id="search" class="search-input" tabindex="-1" placeholder="{{ site.data.ui-text[site.locale].search_placeholder_text | default: 'Enter your search term...' }}" /> | ||
<div id="results" class="results"></div> | ||
{%- when "algolia" -%} | ||
<div class="search-searchbar"></div> | ||
<div class="search-hits"></div> | ||
{%- endcase -%} | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Search | ||
layout: search | ||
permalink: /search/ | ||
--- |