From 5d4d3376f4017731c36e53a78ff8b45aa1159ee0 Mon Sep 17 00:00:00 2001 From: sylhare Date: Mon, 18 Dec 2023 10:23:15 -0500 Subject: [PATCH 1/2] Ignore posts from collection --- _includes/default/search_input.liquid | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/_includes/default/search_input.liquid b/_includes/default/search_input.liquid index 44ff7eb3a0..aa03db8280 100644 --- a/_includes/default/search_input.liquid +++ b/_includes/default/search_input.liquid @@ -26,20 +26,22 @@ {% endunless %} }{% unless forloop.last %},{% endunless %} {% endfor %} -{% if site.collections.size > 0 %},{% endif %} +{% if site.collections.size > 1 %},{% endif %} {% for collection in site.collections %} {% for page in site[collection.label] %} - { - {% if page.excluded or page.title != nil %} - "title" : "{{ page.title | strip_newlines | escape }}", - "category" : "{{ page.category }}", - "tags" : "{{ page.tags | join: ', ' | prepend: " " }}", - "url" : "{{ page.url | relative_url }}", - "date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}", - "excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | jsonify }}, - "content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }} - {% endif %} - }{% unless forloop.last %},{% endunless %} + {% unless collection.label == 'posts' %} + { + {% if page.excluded or page.title != nil %} + "title" : "{{ page.title | strip_newlines | escape }}", + "category" : "{{ page.category }}", + "tags" : "{{ page.tags | join: ', ' | prepend: " " }}", + "url" : "{{ page.url | relative_url }}", + "date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}", + "excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | jsonify }}, + "content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }} + {% endif %} + }{% unless forloop.last %},{% endunless %} + {% endunless %} {% endfor %} {% unless forloop.last %},{% endunless %} {% endfor %} From 292509cfbecf87379307084efa2220ce12a74dce Mon Sep 17 00:00:00 2001 From: sylhare Date: Mon, 18 Dec 2023 10:23:28 -0500 Subject: [PATCH 2/2] Add failsafe --- _includes/default/search_input.liquid | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/_includes/default/search_input.liquid b/_includes/default/search_input.liquid index aa03db8280..deb35dfe0a 100644 --- a/_includes/default/search_input.liquid +++ b/_includes/default/search_input.liquid @@ -28,8 +28,8 @@ {% endfor %} {% if site.collections.size > 1 %},{% endif %} {% for collection in site.collections %} - {% for page in site[collection.label] %} - {% unless collection.label == 'posts' %} + {% unless collection.label == 'posts' or site[collection.label].size == 0 %} + {% for page in site[collection.label] %} { {% if page.excluded or page.title != nil %} "title" : "{{ page.title | strip_newlines | escape }}", @@ -41,8 +41,10 @@ "content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }} {% endif %} }{% unless forloop.last %},{% endunless %} - {% endunless %} - {% endfor %} + {% endfor %} + {% else %} + {} + {% endunless %} {% unless forloop.last %},{% endunless %} {% endfor %} ]