[enh] url prettify

This commit is contained in:
asciimoo 2013-10-25 02:14:26 +02:00
parent d9011f673e
commit ea475ee709
2 changed files with 6 additions and 1 deletions

View file

@ -1,4 +1,4 @@
<div class="result">
<h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
<p class="content"><span class="engines">{{ result.engine }}</span><br />{% if result.content %}{{ result.content|safe }}<br />{% endif %}<span class="url">{{ result.url }}</span></p>
<p class="content"><span class="engines">{{ result.engine }}</span><br />{% if result.content %}{{ result.content|safe }}<br />{% endif %}<span class="url">{{ result.pretty_url }}</span></p>
</div>

View file

@ -79,6 +79,11 @@ def index():
selected_categories.append(ccateg)
query = request_data['q'].encode('utf-8')
results = search(query, request, selected_categories)
for result in results:
if len(result['url']) > 74:
result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
else:
result['pretty_url'] = result['url']
if request_data.get('format') == 'json':
return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json')
template = render('results.html'