File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 % }
You can’t perform that action at this time.
0 commit comments