-
Notifications
You must be signed in to change notification settings - Fork 205
Allow searching of pages & posts #18
Comments
I don't know if this is what you're after, but have you tried using I'm trying that approach and it seems to also include my I have however had issues with using the above approach as it seems to ignore the My code is: ---
---
[
{% for post in site.posts %}
{
"title" : "{{ post.title | escape }}",
"category" : "{{ post.category }}",
"tags" : "{{ post.tags | array_to_sentence_string }}",
"url" : "{{ site.baseurl }}{{ post.url }}",
"date" : "{{ post.date }}",
"formatted-date" : "{{ post.date | date: '%b %-d, %Y' }}",
"type" : "Post"
},
{% endfor %}
{% for page in site.html_pages %}
{
"title" : "{{ page.title | escape }}",
"url" : "{{ site.baseurl }}{{ page.url }}",
"type" : "Page"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
] |
This looks pretty good! Thanks for your reply. Due to the project I am working on I have had to make a slight modification to how the json file outputs, I've had to figure out a way to exclude pages from the search. Here's what I have currently:
Due to how the loop works I couldn't exclude 'non-searchable' pages from the json file as the forloop.last would then be incorrect and the trailing comma would sometimes fail to appear. I believe I also had the 10 items limit issue, my new sample code avoids that but in not really in a clean way. I'm sorry to go into so much detail with my case use, but I feel that explaining my real world usage of the plugin it will help with its development. |
I've been using this JS plugin with a documentation site, which meant I needed to search through pages rather than posts. This is the code I used:
I've swapped the posts for pages, but using an assigned variable so I'm not repeating myself. I've also used the jsonify filter to clean up the content and url incase it has anything that will clash with json syntax.
The only problem is that I had to exclude the search.json and the outputted CSS using two conditional statements, I'm not sure why it thinks they are pages. Thoughts?
The text was updated successfully, but these errors were encountered: