From a14a3f2227e75a3a97784342552fc5bc54f49011 Mon Sep 17 00:00:00 2001 From: nickgarlis Date: Mon, 27 Nov 2017 21:46:00 +0200 Subject: [PATCH] Add option to search in specific collections --- _config.yml | 1 + assets/js/lunr-en.js | 50 ++++++++++++++++++++++++-------------------- docs/_config.yml | 5 +++++ test/_config.yml | 4 ++++ 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/_config.yml b/_config.yml index 78c74025d9bc..4f5af9ba6f26 100644 --- a/_config.yml +++ b/_config.yml @@ -251,3 +251,4 @@ defaults: comments: # true share: true related: true + search: # true diff --git a/assets/js/lunr-en.js b/assets/js/lunr-en.js index d196d5543037..d4e688c16a8f 100644 --- a/assets/js/lunr-en.js +++ b/assets/js/lunr-en.js @@ -14,14 +14,16 @@ var idx = lunr(function () { {% for c in site.collections %} {% assign docs = c.docs %} {% for doc in docs %} - idx.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 %} + {% if doc.search == true %} + idx.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 %} + {% endif %} {% endfor %} {% endfor %} @@ -34,22 +36,24 @@ var store = [ {% endif %} {% assign docs = c.docs %} {% for doc in docs %} - {% if doc.header.teaser %} - {% capture teaser %}{{ doc.header.teaser }}{% endcapture %} - {% else %} - {% assign teaser = site.teaser %} + {% if doc.search == true %} + {% 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 %} {% 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 %}] diff --git a/docs/_config.yml b/docs/_config.yml index 8bb244a65449..be030c2e3f7d 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -203,6 +203,7 @@ defaults: comments: true share: true related: true + search: true # _pages - scope: path: "_pages" @@ -222,6 +223,7 @@ defaults: comments: false sidebar: nav: "docs" + search: true # _recipes - scope: path: "" @@ -231,6 +233,7 @@ defaults: author_profile: true share: true comments: true + search: true # _pets - scope: path: "" @@ -240,6 +243,7 @@ defaults: author_profile: true share: true comment: true + search: true # _portfolio - scope: path: "" @@ -248,6 +252,7 @@ defaults: layout: single author_profile: false share: true + search: true # Sass/SCSS diff --git a/test/_config.yml b/test/_config.yml index 5f5588df30fe..9583e262e039 100644 --- a/test/_config.yml +++ b/test/_config.yml @@ -261,6 +261,7 @@ defaults: read_time: true share: true related: true + search: true # _pages - scope: path: "_pages" @@ -276,6 +277,7 @@ defaults: layout: single author_profile: true share: true + search: true # _pets - scope: path: "" @@ -284,6 +286,7 @@ defaults: layout: single author_profile: true share: true + search: true # _portfolio - scope: path: "" @@ -292,3 +295,4 @@ defaults: layout: single author_profile: false share: true + search: true