-
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.
- Loading branch information
Showing
10 changed files
with
203 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<!-- Including InstantSearch.js library and styling --> | ||
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.6.0/dist/instantsearch.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.6.0/dist/instantsearch.min.css"> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.6.0/dist/instantsearch-theme-algolia.min.css"> | ||
|
||
<script> | ||
// Instanciating InstantSearch.js with Algolia credentials | ||
const search = instantsearch({ | ||
appId: '{{ site.algolia.application_id }}', | ||
indexName: '{{ site.algolia.index_name }}', | ||
apiKey: '{{ site.algolia.search_only_api_key }}' | ||
}); | ||
|
||
// Adding searchbar and results widgets | ||
search.addWidget( | ||
instantsearch.widgets.searchBox({ | ||
container: '#search-searchbar', | ||
placeholder: 'Search into posts...', | ||
poweredBy: true, // This is required if you're on the free Community plan | ||
}) | ||
); | ||
|
||
const hitTemplate = function(hit){ | ||
let isCover = hit.cover; | ||
let articleClass = "post-card"; | ||
if(!isCover) articleClass += " no-image"; | ||
|
||
const title = hit._highlightResult.title.value; | ||
const content = hit._highlightResult.html.value; | ||
console.log(hit._highlightResult); | ||
let template = `<article class="${articleClass}">` | ||
if(isCover){ | ||
template += ` <a class="post-card-image-link" href="{{ site.baseurl }}${hit.url.substring(1)}"> | ||
<div class="post-card-image" style="background-image: url({{ site.baseurl }}${ hit.cover })"></div> | ||
</a>`; | ||
} | ||
|
||
template += `<div class="post-card-content"> | ||
<div class="post-card-content-link"> | ||
<header class="post-card-header">`; | ||
|
||
let date = ''; | ||
if (hit.date) { | ||
date = moment.unix(hit.date).format('MMM D, YYYY'); | ||
template += `<time class="post-card-tags-date" datetime="{{ page.date | date:'%e %B %Y' }}">${date}</time>`; | ||
} | ||
|
||
if('tags' in hit && hit.tags.length){ | ||
template += `<span class="post-card-tags-date">/</span>`; | ||
for(tag_index in hit.tags){ | ||
if(tag_index == hit.tags.length-1) | ||
template += `<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]}</a>`; | ||
else | ||
template += `<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]},</a>`; | ||
|
||
} | ||
} | ||
|
||
template += `</header> | ||
<header class="post-card-header"> | ||
<h2 class="post-card-title">${ title }</h2> | ||
</header> | ||
<section class="post-card-excerpt"> | ||
<p>${ content }...</p> | ||
</section> | ||
</div> | ||
<footer class="post-card-meta"> | ||
</footer> | ||
</div> | ||
</article>`; | ||
|
||
return template; | ||
}; | ||
|
||
search.addWidget( | ||
instantsearch.widgets.hits({ | ||
container: '#search-hits', | ||
templates: { | ||
item: hitTemplate | ||
} | ||
}) | ||
); | ||
|
||
// Starting the search | ||
search.start(); | ||
//hide algolia defaults | ||
$('.ais-search-box--magnifier').hide(); | ||
$('.ais-search-box--powered-by').hide(); | ||
$('.ais-search-box--reset').hide(); | ||
//hide search hits intially | ||
$('#search-hits').hide(); | ||
|
||
function expand(){ | ||
if($('.ais-search-box--input').hasClass('open')){ | ||
$('.site-nav-left').css('visibility', 'visible'); | ||
$('#search-hits').hide(); | ||
$('#posts').show(); | ||
}else{ | ||
$('.site-nav-left').css('visibility', 'hidden'); | ||
$('#search-hits').show(); | ||
$('#posts').hide(); | ||
} | ||
$('.ais-search-box--input').toggleClass('open'); | ||
} | ||
$('.search-icon').on('click', expand); | ||
</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,3 @@ | ||
<svg width="18" height="18" viewBox="0 0 100 100"> | ||
<path fill="#ffffff" fill-rule="evenodd" d="M42.117,12.246 C50.1209,12.246 57.797,15.4257 63.453,21.0858 C69.1132,26.742 72.2928,34.4178 72.2928,42.4218 C72.2928,50.4258 69.1131,58.1018 63.453,63.7578 C57.7968,69.418 50.121,72.5976 42.117,72.5976 C34.1131,72.5976 26.437,69.4179 20.781,63.7578 C15.1208,58.1016 11.9412,50.4258 11.9412,42.4218 C11.9412,34.4178 15.1209,26.7418 20.781,21.0858 C26.4372,15.4256 34.113,12.246 42.117,12.246 L42.117,12.246 Z M76.0828827,67.3362833 C82.3527829,58.7859894 85.2617455,48.0434678 83.9173,37.22271 C82.0618,22.28871 72.3743,9.47671 58.5153,3.61771 L58.51139,3.61771 C53.32389,1.41851 47.74139,0.28961 42.10539,0.29741 L42.117,0.305 C29.058,0.30891 16.742,6.3675 8.769001,16.707 C0.7924008,27.047 -1.933999,40.5 1.382301,53.129 C4.698701,65.758 13.6833,76.137 25.7103,81.223 L25.7103,81.22691 C39.5733,87.08631 55.5113,85.10191 67.5153,76.02771 C67.5852345,75.9748392 67.6549736,75.9217748 67.724517,75.8685177 L91.555,99.6990032 L100.0003,91.253703 L76.0828827,67.3362833 Z"></path> | ||
</svg> |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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