mirror of https://github.com/searx/searx
[ehn] Add a 'featured result feature'm putting on top of the reasults ddg definitions and wikipedia (ugly html / css)
[ehn] Add a templates for videos, so the thumbnails all have the same side
This commit is contained in:
parent
ad72c16050
commit
cf8f444e85
|
@ -35,7 +35,11 @@ def response(resp):
|
|||
for result in dom.xpath(results_xpath):
|
||||
url = base_url + result.xpath(url_xpath)[0]
|
||||
title = p.unescape(extract_text(result.xpath(title_xpath)))
|
||||
content = '<a href="{0}"> <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0]))
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
|
||||
thumbnail = extract_text(result.xpath(content_xpath)[0])
|
||||
content = '<a href="{0}"> <img src="{2}"/> </a>'.format(url, title, thumbnail)
|
||||
results.append({'url': url
|
||||
, 'title': title
|
||||
, 'content': content
|
||||
, 'template':'videos.html'
|
||||
, 'thumbnail': thumbnail})
|
||||
return results
|
||||
|
|
|
@ -26,14 +26,21 @@ def response(resp):
|
|||
url = url[:-1]
|
||||
title = result['title']['$t']
|
||||
content = ''
|
||||
|
||||
thumbnail = ''
|
||||
if len(result['media$group']['media$thumbnail']):
|
||||
content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, result['media$group']['media$thumbnail'][0]['url'])
|
||||
thumbnail = result['media$group']['media$thumbnail'][0]['url']
|
||||
content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, thumbnail)
|
||||
if len(content):
|
||||
content += '<br />' + result['content']['$t']
|
||||
else:
|
||||
content = result['content']['$t']
|
||||
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
results.append({'url': url
|
||||
, 'title': title
|
||||
, 'content': content
|
||||
, 'template':'videos.html'
|
||||
, 'thumbnail':thumbnail})
|
||||
|
||||
return results
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ a { text-decoration: none; color: #1a11be; }
|
|||
a:visited { color: #7b11be; }
|
||||
|
||||
.result { margin: 19px 0 18px 0; padding: 0; max-width: 55em; clear: both; }
|
||||
.result:hover { background: #e8e7e6; }
|
||||
.result_title { margin-bottom: 0; }
|
||||
.result h3 { font-size: 1em; word-wrap:break-word; margin: 5px 0 1px 0; padding: 0 }
|
||||
.result .content { font-size: 0.8em; margin: 0; padding: 0; max-width: 54em; word-wrap:break-word; line-height: 1.24; }
|
||||
|
@ -143,6 +144,13 @@ tr:hover td { background: #DDDDDD; }
|
|||
|
||||
#result_count { font-size: 0.8em; margin: 2px 0 2px 0; padding: 0 }
|
||||
|
||||
#fr { padding: 2px 6px;
|
||||
display: inline-block;
|
||||
background: #ECF0F1;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #3498DB;;
|
||||
width:55em;}
|
||||
|
||||
#suggestions { position: absolute; left: 54em; width: 12em; margin: 0 2px 5px 5px; padding: 0 2px 2px 2px; }
|
||||
#suggestions span { display: block; font-size: 0.8em; margin: 0 2px 10px 2px; padding: 0; }
|
||||
#suggestions form { display: block; }
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<div class="result">
|
||||
<p>
|
||||
<h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
|
||||
<a href="{{ result.url }}"><img width="300" height="170" src="{{ result.thumbnail }}" title={{ result.title }} alt=" {{ result.title }}"/></a>
|
||||
<p class="url">{{ result.url }}</p>
|
||||
</p>
|
||||
</div>
|
|
@ -9,9 +9,24 @@
|
|||
{% if suggestions %}
|
||||
<div id="suggestions"><span>Suggestions: </span>{% for suggestion in suggestions %}<form method="post" action="/"><input type="hidden" name="q" value="{{suggestion}}"><input type="submit" value="{{ suggestion }}" /></form>{% endfor %}</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div id ="result_count">
|
||||
Number of results: {{ number_of_results }}
|
||||
</div>
|
||||
{% if featured_results %}
|
||||
<div id="fr">
|
||||
|
||||
{% for result in featured_results %}
|
||||
{% if result['template'] %}
|
||||
{% include 'result_templates/'+result['template'] %}
|
||||
{% else %}
|
||||
{% include 'result_templates/default.html' %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for result in results %}
|
||||
{% if result['template'] %}
|
||||
{% include 'result_templates/'+result['template'] %}
|
||||
|
|
|
@ -125,6 +125,7 @@ def index():
|
|||
|
||||
results, suggestions = search(query, request, selected_engines)
|
||||
|
||||
featured_results = []
|
||||
for result in results:
|
||||
if request_data.get('format', 'html') == 'html':
|
||||
if 'content' in result:
|
||||
|
@ -139,6 +140,10 @@ def index():
|
|||
else:
|
||||
result['pretty_url'] = result['url']
|
||||
|
||||
if 'wikipedia' in result['engines'] or 'ddg definitions' in result['engines']:
|
||||
featured_results.append(result)
|
||||
results.remove(result)
|
||||
|
||||
if request_data.get('format') == 'json':
|
||||
return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json')
|
||||
elif request_data.get('format') == 'csv':
|
||||
|
@ -167,7 +172,8 @@ def index():
|
|||
,results=results
|
||||
,q=request_data['q']
|
||||
,selected_categories=selected_categories
|
||||
,number_of_results=len(results)
|
||||
,number_of_results=len(results)+len(featured_results)
|
||||
,featured_results=featured_results
|
||||
,suggestions=suggestions
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue