Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update search_json to handle empty collection #445

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
sylhare marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
{% endunless %}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% if site.collections.size > 1 %},{% endif %}
{% for collection in site.collections %}
{% 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 }}",
"category" : "{{ page.category }}",
Expand All @@ -41,11 +40,8 @@
"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 %}
}
{% endfor %}
{% else %}
{}
{% endunless %}
{% unless forloop.last %},{% endunless %}
{% endfor %}
]
4 changes: 2 additions & 2 deletions assets/data/search.liquid
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
---
{% comment %}
The json is created in search_input.liquid and included here to be compresed
The json is created in search_json.liquid and included here to be compressed
{% endcomment %}
{% capture _search %}{% include default/search_input.liquid %}{% endcapture %}
{% capture _search %}{% include default/search_json.liquid %}{% endcapture %}
{% assign emptyField = '{ },' %}
{{ _search | split: " " | join: " " | remove: emptyField }}