Skip to content

Commit fc2b908

Browse files
committed
[doc] Fix search index (#5618)
Merge pull request #5618 from adangel:doc/fix-search
2 parents 5500e26 + 1d178cb commit fc2b908

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

docs/_plugins/custom_filters.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ def random_alphabetic(length)
106106
('a'..'z').to_a.shuffle[0, length].join
107107
end
108108

109+
def escape_json(text)
110+
if text
111+
res = text
112+
res = res.gsub(/\\/, '\\\\')
113+
res = res.gsub(/"/, '\\"')
114+
res = res.gsub(/\n/, '\\n')
115+
res = res.gsub(/\r/, '\\r')
116+
res = res.gsub(/\f/, '\\f')
117+
res = res.gsub(/\t/, '\\t')
118+
res = res.gsub(/\b/, '\\b')
119+
end
120+
end
109121

110122
private
111123

docs/search.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ search: exclude
1616
"tags": "{{ page.tags }}",
1717
"keywords": "{{rule}}",
1818
"url": "{{ page.url | remove: "/"}}#{{ rule | downcase }}",
19-
"summary": "{{page.summary | strip }}"
19+
"summary": "{{page.summary | strip | escape_json }}"
2020
}
2121
{% unless forloop.last %},{% endunless %}
2222
{% endfor %}
@@ -26,7 +26,7 @@ search: exclude
2626
"tags": "{{ page.tags }}",
2727
"keywords": "{{page.keywords}}",
2828
"url": "{{ page.url | remove: "/"}}",
29-
"summary": "{{page.summary | strip }}"
29+
"summary": "{{page.summary | strip | escape_json }}"
3030
}
3131
{% endif %}
3232

@@ -42,7 +42,7 @@ search: exclude
4242
"tags": "{{ post.tags }}",
4343
"keywords": "{{post.keywords}}",
4444
"url": "{{ post.url | remove: "/" }}",
45-
"summary": "{{post.summary | strip }}"
45+
"summary": "{{post.summary | strip | escape_json }}"
4646
}
4747
{% unless forloop.last %},{% endunless %}
4848
{% endfor %}

0 commit comments

Comments
 (0)