fix to search.json to strip out tab characters from search.son

these tab characters can make your json invalid
This commit is contained in:
Tom Johnson
2015-10-05 14:24:02 -07:00
parent 841c215855
commit 7e351a08ef
2 changed files with 5 additions and 3 deletions

View File

@ -32,11 +32,13 @@ The search.json file already tries to strip out content that would otherwise mak
```json ```json
{% raw %} {% raw %}
"body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' }}", "body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' | replace: '^t', ' ' }}",
{% endraw %} {% endraw %}
``` ```
However, it's possible that the formatting may not account for all the scenarios that would invalidate the JSON. (Sometimes it's an extra comma after the last item that makes it invalid.) Note that the last replace, `| replace: '^t', ' ' `, looks for any tab character and replaces it with four spaces. Yes, an innocent little tab character invalidates JSON. Geez. If you run into other problematic formatting, you can use regex expressions to find and replace the content. See [Regular Expressions](http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/regular_expressions.html) for details on finding and replacing code.
It's possible that the formatting may not account for all the scenarios that would invalidate the JSON. (Sometimes it's an extra comma after the last item that makes it invalid.)
{% if site.audience == "designers" %} {% if site.audience == "designers" %}
## Customizing search results ## Customizing search results

View File

@ -12,7 +12,7 @@ search: exclude
"keywords": "{{page.keywords}}", "keywords": "{{page.keywords}}",
"url": "{{ page.url | replace: '/','' }}", "url": "{{ page.url | replace: '/','' }}",
"summary": "{{page.summary}}", "summary": "{{page.summary}}",
"body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' }}" "body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"'| replace: '^t', ' ' }}"
}, },
{% endunless %} {% endunless %}