Minimize JSON data (#1449)
* Remove Lunr trimmer & bring back colons * Add Greek Stemmer * Translate search_placeholder_text and results_found to Greek * Minimize JSON data * Truncate Words * Move store variable into a new file * Move Lunr files into a new folder * Add defer to lunr scripts * Add search_full_content switch
This commit is contained in:
parent
76b02a8c15
commit
3fb63f302d
|
@ -8,7 +8,7 @@
|
||||||
minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise"
|
minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise"
|
||||||
|
|
||||||
# Site Settings
|
# Site Settings
|
||||||
locale : "en"
|
locale : "en-US"
|
||||||
title : "Site Title"
|
title : "Site Title"
|
||||||
title_separator : "-"
|
title_separator : "-"
|
||||||
name : "Your Name"
|
name : "Your Name"
|
||||||
|
@ -52,6 +52,7 @@ reCaptcha:
|
||||||
atom_feed:
|
atom_feed:
|
||||||
path : # blank (default) uses feed.xml
|
path : # blank (default) uses feed.xml
|
||||||
search : # true, false (default)
|
search : # true, false (default)
|
||||||
|
search_full_content : # true, false (default)
|
||||||
|
|
||||||
# SEO Related
|
# SEO Related
|
||||||
google_site_verification :
|
google_site_verification :
|
||||||
|
|
|
@ -20,8 +20,9 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{% assign lang = "en" %}
|
{% assign lang = "en" %}
|
||||||
{% endcase %}
|
{% endcase %}
|
||||||
<script src="{{ '/assets/js/lunr.min.js' | absolute_url }}"></script>
|
<script defer src="{{ '/assets/js/lunr/lunr.min.js' | absolute_url }}"></script>
|
||||||
<script src="{{ '/assets/js/lunr-' | append: lang | append: '.js' | absolute_url }}"></script>
|
<script defer src="{{ '/assets/js/lunr/lunr-store.js' | absolute_url }}"></script>
|
||||||
|
<script defer src="{{ '/assets/js/lunr/lunr-' | append: lang | append: '.js' | absolute_url }}"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% include analytics.html %}
|
{% include analytics.html %}
|
||||||
|
|
|
@ -11,50 +11,19 @@ var idx = lunr(function () {
|
||||||
|
|
||||||
this.pipeline.remove(lunr.trimmer)
|
this.pipeline.remove(lunr.trimmer)
|
||||||
|
|
||||||
{% assign count = 0 %}
|
for (var item in store) {
|
||||||
{% for c in site.collections %}
|
this.add({
|
||||||
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
title: store[item].title,
|
||||||
{% for doc in docs %}
|
excerpt: store[item].excerpt,
|
||||||
this.add({
|
categories: store[item].categories,
|
||||||
title: {{ doc.title | jsonify }},
|
tags: store[item].tags,
|
||||||
excerpt: {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
|
id: item
|
||||||
categories: {{ doc.categories | jsonify }},
|
})
|
||||||
tags: {{ doc.tags | jsonify }},
|
}
|
||||||
id: {{ count }}
|
|
||||||
})
|
|
||||||
{% assign count = count | plus: 1 %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log( jQuery.type(idx) );
|
console.log( jQuery.type(idx) );
|
||||||
|
|
||||||
var store = [
|
|
||||||
{% for c in site.collections %}
|
|
||||||
{% if forloop.last %}
|
|
||||||
{% assign l = true %}
|
|
||||||
{% endif %}
|
|
||||||
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
|
||||||
{% for doc in docs %}
|
|
||||||
{% 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 %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}]
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('input#search').on('keyup', function () {
|
$('input#search').on('keyup', function () {
|
||||||
var resultdiv = $('#results');
|
var resultdiv = $('#results');
|
||||||
|
@ -62,7 +31,7 @@ $(document).ready(function() {
|
||||||
var result =
|
var result =
|
||||||
idx.query(function (q) {
|
idx.query(function (q) {
|
||||||
query.split(lunr.tokenizer.separator).forEach(function (term) {
|
query.split(lunr.tokenizer.separator).forEach(function (term) {
|
||||||
q.term(term, { boost: 100 })
|
q.term(term, { boost: 100 })
|
||||||
if(query.lastIndexOf(" ") != query.length-1){
|
if(query.lastIndexOf(" ") != query.length-1){
|
||||||
q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
|
q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
|
||||||
}
|
}
|
||||||
|
@ -85,7 +54,7 @@ $(document).ready(function() {
|
||||||
'<div class="archive__item-teaser">'+
|
'<div class="archive__item-teaser">'+
|
||||||
'<img src="'+store[ref].teaser+'" alt="">'+
|
'<img src="'+store[ref].teaser+'" alt="">'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt.split(" ").splice(0,20).join(" ")+'...</p>'+
|
||||||
'</article>'+
|
'</article>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
@ -96,7 +65,7 @@ $(document).ready(function() {
|
||||||
'<h2 class="archive__item-title" itemprop="headline">'+
|
'<h2 class="archive__item-title" itemprop="headline">'+
|
||||||
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
||||||
'</h2>'+
|
'</h2>'+
|
||||||
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt.split(" ").splice(0,20).join(" ")+'...</p>'+
|
||||||
'</article>'+
|
'</article>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
|
@ -464,50 +464,19 @@ var idx = lunr(function () {
|
||||||
this.pipeline.add(greekStemmer)
|
this.pipeline.add(greekStemmer)
|
||||||
this.pipeline.remove(lunr.stemmer)
|
this.pipeline.remove(lunr.stemmer)
|
||||||
|
|
||||||
{% assign count = 0 %}
|
for (var item in store) {
|
||||||
{% for c in site.collections %}
|
this.add({
|
||||||
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
title: store[item].title,
|
||||||
{% for doc in docs %}
|
excerpt: store[item].excerpt,
|
||||||
this.add({
|
categories: store[item].categories,
|
||||||
title: {{ doc.title | jsonify }},
|
tags: store[item].tags,
|
||||||
excerpt: {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
|
id: item
|
||||||
categories: {{ doc.categories | jsonify }},
|
})
|
||||||
tags: {{ doc.tags | jsonify }},
|
}
|
||||||
id: {{ count }}
|
|
||||||
})
|
|
||||||
{% assign count = count | plus: 1 %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log( jQuery.type(idx) );
|
console.log( jQuery.type(idx) );
|
||||||
|
|
||||||
var store = [
|
|
||||||
{% for c in site.collections %}
|
|
||||||
{% if forloop.last %}
|
|
||||||
{% assign l = true %}
|
|
||||||
{% endif %}
|
|
||||||
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
|
||||||
{% for doc in docs %}
|
|
||||||
{% 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 %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}]
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('input#search').on('keyup', function () {
|
$('input#search').on('keyup', function () {
|
||||||
var resultdiv = $('#results');
|
var resultdiv = $('#results');
|
||||||
|
@ -538,7 +507,7 @@ $(document).ready(function() {
|
||||||
'<div class="archive__item-teaser">'+
|
'<div class="archive__item-teaser">'+
|
||||||
'<img src="'+store[ref].teaser+'" alt="">'+
|
'<img src="'+store[ref].teaser+'" alt="">'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt.split(" ").splice(0,20).join(" ")+'...</p>'+
|
||||||
'</article>'+
|
'</article>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
@ -549,7 +518,7 @@ $(document).ready(function() {
|
||||||
'<h2 class="archive__item-title" itemprop="headline">'+
|
'<h2 class="archive__item-title" itemprop="headline">'+
|
||||||
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
'<a href="'+store[ref].url+'" rel="permalink">'+store[ref].title+'</a>'+
|
||||||
'</h2>'+
|
'</h2>'+
|
||||||
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt+'</p>'+
|
'<p class="archive__item-excerpt" itemprop="description">'+store[ref].excerpt.split(" ").splice(0,20).join(" ")+'...</p>'+
|
||||||
'</article>'+
|
'</article>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
36
assets/js/lunr/lunr-store.js
Normal file
36
assets/js/lunr/lunr-store.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
layout: null
|
||||||
|
---
|
||||||
|
|
||||||
|
var store = [
|
||||||
|
{% for c in site.collections %}
|
||||||
|
{% if forloop.last %}
|
||||||
|
{% assign l = true %}
|
||||||
|
{% endif %}
|
||||||
|
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
|
||||||
|
{% for doc in docs %}
|
||||||
|
{% if doc.header.teaser %}
|
||||||
|
{% capture teaser %}{{ doc.header.teaser }}{% endcapture %}
|
||||||
|
{% else %}
|
||||||
|
{% assign teaser = site.teaser %}
|
||||||
|
{% endif %}
|
||||||
|
{
|
||||||
|
"title": {{ doc.title | jsonify }},
|
||||||
|
"excerpt":
|
||||||
|
{% if site.search_full_content == true %}
|
||||||
|
{{ doc.content | strip_html | strip_newlines | jsonify }},
|
||||||
|
{% else %}
|
||||||
|
{{ doc.content | strip_html | strip_newlines | truncatewords: 50 | jsonify }},
|
||||||
|
{% endif %}
|
||||||
|
"categories": {{ doc.categories | jsonify }},
|
||||||
|
"tags": {{ doc.tags | jsonify }},
|
||||||
|
"url": {{ doc.url | absolute_url | jsonify }},
|
||||||
|
"teaser":
|
||||||
|
{% if teaser contains "://" %}
|
||||||
|
{{ teaser | jsonify }}
|
||||||
|
{% else %}
|
||||||
|
{{ teaser | absolute_url | jsonify }}
|
||||||
|
{% endif %}
|
||||||
|
}{% unless forloop.last and l %},{% endunless %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}]
|
|
@ -56,6 +56,7 @@ atom_feed:
|
||||||
path : # blank (default) uses feed.xml
|
path : # blank (default) uses feed.xml
|
||||||
|
|
||||||
search : true # true, false (default)
|
search : true # true, false (default)
|
||||||
|
search_full_content : true # true, false (default)
|
||||||
|
|
||||||
# SEO Related
|
# SEO Related
|
||||||
google_site_verification : "UQj93ERU9zgECodaaXgVpkjrFn9UrDMEzVamacSoQ8Y" # Replace this with your ID, or delete
|
google_site_verification : "UQj93ERU9zgECodaaXgVpkjrFn9UrDMEzVamacSoQ8Y" # Replace this with your ID, or delete
|
||||||
|
|
|
@ -9,7 +9,7 @@ theme : "minimal-mistakes-jekyll"
|
||||||
minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise"
|
minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise"
|
||||||
|
|
||||||
# Site Settings
|
# Site Settings
|
||||||
locale : "en"
|
locale : "en-US"
|
||||||
title : "Minimal Mistakes Development Test Site"
|
title : "Minimal Mistakes Development Test Site"
|
||||||
title_separator : "-"
|
title_separator : "-"
|
||||||
name : "Your Name"
|
name : "Your Name"
|
||||||
|
@ -50,6 +50,7 @@ staticman:
|
||||||
atom_feed:
|
atom_feed:
|
||||||
path : # blank (default) uses feed.xml
|
path : # blank (default) uses feed.xml
|
||||||
search : true # true, false (default)
|
search : true # true, false (default)
|
||||||
|
search_full_content : true # true, false (default)
|
||||||
|
|
||||||
# SEO Related
|
# SEO Related
|
||||||
google_site_verification :
|
google_site_verification :
|
||||||
|
|
Loading…
Reference in a new issue