Преглед на файлове

Merge pull request #105 from talha131/minify-json

Minify JSON to improve search speed
Justin Mayer преди 11 години
родител
ревизия
744c1620f5
променени са 1 файла, в които са добавени 6 реда и са изтрити 4 реда
  1. 6 4
      tipue_search/tipue_search.py

+ 6 - 4
tipue_search/tipue_search.py

@@ -33,10 +33,12 @@ class Tipue_Search_JSON_Generator(object):
         if getattr(page, 'status', 'published') != 'published':
             return
 
-        page_title = page.title
+        soup_title = BeautifulSoup(page.title.replace(' ', ' '))
+        page_title = soup_title.get_text(' ', strip=True).replace('“', '"').replace('”', '"').replace('’', "'")
 
-        soup = BeautifulSoup(page.content, 'html.parser')
-        page_text = soup.get_text()
+        soup_text = BeautifulSoup(page.content)
+        page_text = soup_text.get_text(' ', strip=True).replace('“', '"').replace('”', '"').replace('’', "'").replace('¶', ' ')
+        page_text = ' '.join(page_text.split())
 
         if getattr(page, 'category') == 'None':
             page_category = ''
@@ -65,7 +67,7 @@ class Tipue_Search_JSON_Generator(object):
         root_node = {'pages': self.json_nodes}
 
         with open(path, 'w', encoding='utf-8') as fd:
-            json.dump(root_node, fd, indent=4)
+            json.dump(root_node, fd, separators=(',', ':'))
 
 
 def get_generators(generators):