module Search

Public Class Methods

add_to_index(file, slug, title, content) click to toggle source
# 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) click to toggle source

Some special handling for sanitizing the search json

# 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!(/\</, '&lt;') if str[/\</]
  str.gsub!(/\>/, '&gt;') if str[/\>/]
  str
end