Skip to content

Commit

Permalink
Compress search index
Browse files Browse the repository at this point in the history
Remove all unnesecary whitespace. Closes mkdocs#1128.
  • Loading branch information
waylan committed Jan 31, 2018
1 parent 2c544d6 commit da3dc1d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mkdocs/contrib/search/search_index.py
Expand Up @@ -2,6 +2,7 @@

from __future__ import unicode_literals

import re
import json
from mkdocs import utils

Expand Down Expand Up @@ -37,9 +38,12 @@ def _add_entry(self, title, text, loc):
A simple wrapper to add an entry and ensure the contents
is UTF8 encoded.
"""
text = text.replace('\u00a0', ' ')
text = re.sub(r'[ \t\n\r\f\v]+', ' ', text.strip())

self._entries.append({
'title': title,
'text': utils.text_type(text.strip().encode('utf-8'), encoding='utf-8'),
'text': utils.text_type(text.encode('utf-8'), encoding='utf-8'),
'location': loc
})

Expand Down Expand Up @@ -92,7 +96,7 @@ def generate_search_index(self):
page_dicts = {
'docs': self._entries,
}
return json.dumps(page_dicts, sort_keys=True, indent=4)
return json.dumps(page_dicts, sort_keys=True, separators=(',', ':'))

def strip_tags(self, html):
"""strip html tags from data"""
Expand Down

0 comments on commit da3dc1d

Please sign in to comment.