Skip to content

Instantly share code, notes, and snippets.

@digitigradeit
Created August 2, 2023 08:07
Show Gist options
  • Save digitigradeit/34492b6ef4351f48d8ad94504b94821d to your computer and use it in GitHub Desktop.
Save digitigradeit/34492b6ef4351f48d8ad94504b94821d to your computer and use it in GitHub Desktop.
Simple Jekyll Search JSON file
---
layout: none
---
{% capture json %}
{% assign first = true %}
[
{% for collection in site.collections %}
{% for item in collection %}
{% for item in site[item.label] %}
{% if item.title != null and item.title != empty %}
{% unless first %},{% endunless %}{
"title": {{item.title | strip_html | jsonify}},
"subtitle": {{item.subtitle | strip_html | jsonify}},
"content": {{item.content | markdownify | strip_html | jsonify}},
"link": "{{ site.baseurl }}{{ item.url }}",
"date": "{{ item.date }}",
"excerpt": "{{ item.snippet }}",
"search_omit": "{{ item.search_omit }}"
}
{% assign first = false %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% for post in site.posts %}
{% if post.title != null and post.title != empty %}
{% unless first %},{% endunless %}{
"title": {{post.title | strip_html | jsonify}},
"subtitle": {{post.subtitle | strip_html | jsonify}},
"content": {{post.content | markdownify | strip_html | jsonify}},
"link": "{{ site.baseurl }}{{ post.url }}",
"date": "{{ post.date }}",
"excerpt": "{{ post.snippet }}",
"search_omit": "{{ post.search_omit }}"
}
{% assign first = false %}
{% endif %}
{% endfor %}
{% for page in site.pages %}
{% if page.title != null and page.title != empty %}
{% unless first %},{% endunless %}{
"title": {{page.title | strip_html | jsonify}},
"subtitle": {{page.subtitle | strip_html | jsonify}},
"content": {{page.content | strip_html | jsonify}},
"link": "{{ site.baseurl }}{{ page.url | replace: 'index.html', '' }}",
"date": {{ page.date | jsonify }},
"excerpt": {{ page.description | jsonify }},
"search_omit": "{{ page.search_omit }}"
}
{% assign first = false %}
{% endif %}
{% endfor %}
]
{% endcapture %}
{{ json | strip_newlines }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment