Module: Search
- Defined in:
- lib/extensions/utils/search.rb
Class Method Summary collapse
- .add_to_index(file, slug, title, content) ⇒ Object
-
.sanitize_json(str) ⇒ Object
Some special handling for sanitizing the search json.
Class Method Details
.add_to_index(file, slug, title, content) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/extensions/utils/search.rb', line 13 def self.add_to_index(file, slug, title, content) section = %( "#{slug}": { "id": "#{slug}", "title": "#{title}", "url": "#{file}", "content": "#{sanitize_json(content)}" },\n) end |
.sanitize_json(str) ⇒ Object
Some special handling for sanitizing the search json
3 4 5 6 7 8 9 10 11 |
# File 'lib/extensions/utils/search.rb', line 3 def self.sanitize_json(str) special_chars = /"|\n|«|» |\{|\}|…/ str.gsub!(special_chars, ' ') str.gsub!(/\s+/, ' ') str.gsub!(/Unresolved directive.+\[\]/, '') str.gsub!(/\</, '<') if str[/\</] str.gsub!(/\>/, '>') if str[/\>/] str end |