2017-11-15 20:43:31 +01:00
|
|
|
---
|
2017-11-20 21:03:51 +01:00
|
|
|
layout: null
|
2017-11-15 20:43:31 +01:00
|
|
|
---
|
2017-11-15 21:50:29 +01:00
|
|
|
|
2017-11-15 20:43:31 +01:00
|
|
|
var idx = lunr(function () {
|
2017-12-28 19:56:10 +01:00
|
|
|
this.field('title')
|
2017-11-15 20:43:31 +01:00
|
|
|
this.field('excerpt')
|
|
|
|
this.field('categories')
|
|
|
|
this.field('tags')
|
|
|
|
this.ref('id')
|
|
|
|
|
2017-12-28 19:56:10 +01:00
|
|
|
{% assign count = 0 %}
|
|
|
|
{% for c in site.collections %}
|
|
|
|
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
|
|
|
{% for doc in docs %}
|
|
|
|
this.add({
|
|
|
|
title: {{ doc.title | jsonify }},
|
|
|
|
excerpt: {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
|
|
|
|
categories: {{ doc.categories | jsonify }},
|
|
|
|
tags: {{ doc.tags | jsonify }},
|
|
|
|
id: {{ count }}
|
|
|
|
})
|
|
|
|
{% assign count = count | plus: 1 %}
|
|
|
|
{% endfor %}
|
2017-11-15 20:43:31 +01:00
|
|
|
{% endfor %}
|
2017-12-28 19:56:10 +01:00
|
|
|
});
|
2017-11-15 20:43:31 +01:00
|
|
|
|
|
|
|
console.log( jQuery.type(idx) );
|
|
|
|
|
|
|
|
var store = [
|
|
|
|
{% for c in site.collections %}
|
|
|
|
{% if forloop.last %}
|
|
|
|
{% assign l = true %}
|
|
|
|
{% endif %}
|
2017-11-28 15:30:33 +01:00
|
|
|
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
2017-11-15 20:43:31 +01:00
|
|
|
{% for doc in docs %}
|
2017-11-28 15:30:33 +01:00
|
|
|
{% if doc.header.teaser %}
|
|
|
|
{% capture teaser %}{{ doc.header.teaser }}{% endcapture %}
|
|
|
|
{% else %}
|
|
|
|
{% assign teaser = site.teaser %}
|
|
|
|
{% endif %}
|
|
|
|
{
|
|
|
|
"title": {{ doc.title | jsonify }},
|
|
|
|
"url": {{ doc.url | absolute_url | jsonify }},
|
|
|
|
"excerpt": {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
|
|
|
|
"teaser":
|
|
|
|
{% if teaser contains "://" %}
|
|
|
|
{{ teaser | jsonify }}
|
|
|
|
{% else %}
|
|
|
|
{{ teaser | absolute_url | jsonify }}
|
|
|
|
{% endif %}
|
|
|
|
}{% unless forloop.last and l %},{% endunless %}
|
2017-11-15 20:43:31 +01:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}]
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('input#search').on('keyup', function () {
|
|
|
|
var resultdiv = $('#results');
|
2017-12-28 19:56:10 +01:00
|
|
|
var query = $(this).val().toLowerCase().replace(":", "");
|
|
|
|
var result =
|
|
|
|
idx.query(function (q) {
|
|
|
|
query.split(lunr.tokenizer.separator).forEach(function (term) {
|
|
|
|
q.term(term, { boost: 100 })
|
|
|
|
if(query.lastIndexOf(" ") != query.length-1){
|
|
|
|
q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
|
|
|
|
}
|
|
|
|
if (term != ""){
|
|
|
|
q.term(term, { usePipeline: false, editDistance: 1, boost: 1 })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2017-11-15 20:43:31 +01:00
|
|
|
resultdiv.empty();
|
2017-12-07 14:56:14 +01:00
|
|
|
resultdiv.prepend('<p class="results__found">'+result.length+' {{ site.data.ui-text[site.locale].results_found | default: "Result(s) found" }}</p>');
|
2017-11-15 20:43:31 +01:00
|
|
|
for (var item in result) {
|
|
|
|
var ref = result[item].ref;
|
|
|
|
if(store[ref].teaser){
|
|
|
|
var searchitem =
|
2017-11-15 21:50:29 +01:00
|
|
|
'<div class="list__item">'+
|
2017-11-15 20:43:31 +01:00
|
|
|
'<article class="archive__item" itemscope itemtype="http://schema.org/CreativeWork">'+
|
|
|
|
'<h2 class="archive__item-title" itemprop="headline">'+
|
|
|
|
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
|
|
|
'</h2>'+
|
2017-11-15 21:50:29 +01:00
|
|
|
'<div class="archive__item-teaser">'+
|
|
|
|
'<img src="'+store[ref].teaser+'" alt="">'+
|
|
|
|
'</div>'+
|
2017-11-15 20:43:31 +01:00
|
|
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
|
|
|
'</article>'+
|
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var searchitem =
|
2017-11-15 21:50:29 +01:00
|
|
|
'<div class="list__item">'+
|
2017-11-15 20:43:31 +01:00
|
|
|
'<article class="archive__item" itemscope itemtype="http://schema.org/CreativeWork">'+
|
|
|
|
'<h2 class="archive__item-title" itemprop="headline">'+
|
|
|
|
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
|
|
|
'</h2>'+
|
|
|
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
|
|
|
'</article>'+
|
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
resultdiv.append(searchitem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|