Browse Source

[mod] pretty url separation

Adam Tauber 10 years ago
parent
commit
8de97dac03
2 changed files with 10 additions and 6 deletions
  1. 7
    0
      searx/utils.py
  2. 3
    6
      searx/webapp.py

+ 7
- 0
searx/utils.py View File

@@ -218,3 +218,10 @@ def dict_subset(d, properties):
218 218
         if k in d:
219 219
             result[k] = d[k]
220 220
     return result
221
+
222
+
223
+def prettify_url(url):
224
+    if len(url) > 74:
225
+        return u'{0}[...]{1}'.format(url[:35], url[-35:])
226
+    else:
227
+        return url

+ 3
- 6
searx/webapp.py View File

@@ -42,7 +42,8 @@ from searx.engines import (
42 42
 )
43 43
 from searx.utils import (
44 44
     UnicodeWriter, highlight_content, html_to_text, get_themes,
45
-    get_static_files, get_result_templates, gen_useragent, dict_subset
45
+    get_static_files, get_result_templates, gen_useragent, dict_subset,
46
+    prettify_url
46 47
 )
47 48
 from searx.version import VERSION_STRING
48 49
 from searx.languages import language_codes
@@ -330,11 +331,7 @@ def index():
330 331
             result['title'] = ' '.join(html_to_text(result['title'])
331 332
                                        .strip().split())
332 333
 
333
-        if len(result['url']) > 74:
334
-            url_parts = result['url'][:35], result['url'][-35:]
335
-            result['pretty_url'] = u'{0}[...]{1}'.format(*url_parts)
336
-        else:
337
-            result['pretty_url'] = result['url']
334
+        result['pretty_url'] = prettify_url(result['url'])
338 335
 
339 336
         # TODO, check if timezone is calculated right
340 337
         if 'publishedDate' in result: