Simplify search: true conditionals

Replace `unless` tags with `where_exp` to test if `search: false`.
This commit is contained in:
Michael Rose 2017-11-28 09:30:33 -05:00
parent 1fcda6f988
commit 7b3ddfefdf

View file

@ -12,18 +12,16 @@ var idx = lunr(function () {
{% assign count = 0 %}
{% for c in site.collections %}
{% assign docs = c.docs %}
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
{% for doc in docs %}
{% unless doc.search == false %}
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 %}
{% endunless %}
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 %}
{% endfor %}
{% endfor %}
@ -34,26 +32,24 @@ var store = [
{% if forloop.last %}
{% assign l = true %}
{% endif %}
{% assign docs = c.docs %}
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
{% for doc in docs %}
{% unless doc.search == false %}
{% 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 %}
{% endunless %}
{% 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 %}]