on master help sign in
[mod] pretty url separation
8de97daAdam Tauber
searx/utils.py+7
@@ -218,3 +218,10 @@ def dict_subset(d, properties):
218 if k in d:
218 if k in d:
219 result[k] = d[k]
219 result[k] = d[k]
220 return result
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
searx/webapp.py+3−6
@@ -42,7 +42,8 @@ from searx.engines import (
42)
42)
43from searx.utils import (
43from searx.utils import (
44 UnicodeWriter, highlight_content, html_to_text, get_themes,
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)
47from searx.version import VERSION_STRING
48from searx.version import VERSION_STRING
48from searx.languages import language_codes
49from searx.languages import language_codes
@@ -330,11 +331,7 @@ def index():
330 result['title'] = ' '.join(html_to_text(result['title'])
331 result['title'] = ' '.join(html_to_text(result['title'])
331 .strip().split())
332 .strip().split())
332
333
333− if len(result['url']) > 74:
334+ result['pretty_url'] = prettify_url(result['url'])
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']
338
335
339 # TODO, check if timezone is calculated right
336 # TODO, check if timezone is calculated right
340 if 'publishedDate' in result:
337 if 'publishedDate' in result: