Skip to content
Snippets Groups Projects
Unverified Commit c8a8ce33 authored by Ben Goldhaber's avatar Ben Goldhaber Committed by GitHub
Browse files

Fix trailing comma bug in search-data.json

If you exclude the last page in the site.html_pages through exclude_true you end up violating the assumption in the for loop that the last page won't have a trailing comma. This breaks the json data that is served to the front end.

I removed the forloop.last check and instead assign a temporary variable to check for the first non-excluded page, and then add the comma before the next non-excluded entry.
parent 721484a2
No related branches found
No related tags found
No related merge requests found
---
---
{
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
"id": "{{ forloop.index0 }}",
"title": "{{ page.title | replace: '&', '&' }}",
"content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
"url": "{{ page.url | absolute_url }}",
"relUrl": "{{ page.url }}"
}{% unless forloop.last %},{% endunless %}
{% endif %}{% endfor %}
{% assign comma = false %}
{% for page in site.html_pages %}{% if page.search_exclude != true %}{% if comma == true%},{% endif %}
"{{ forloop.index0 }}": {
"id": "{{ forloop.index0 }}",
"title": "{{ page.title | replace: '&', '&' }}",
"content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
"url": "{{ page.url | absolute_url }}",
"relUrl": "{{ page.url }}"
}{% assign comma = true %}
{% endif %}{% endfor %}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment